sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.75k stars 1.66k forks source link

Closed Connection - Reason: An exception has occurred while connecting. #484

Open salmanian opened 6 years ago

salmanian commented 6 years ago

i am using websocket sharp in unity and in the server side i use SignalR, it's ok and everything works well but my problem is sometimes when i start to connect, the websocket sharp cause this error: "Closed Connection - An exception has occurred while connecting" and after that everytime i start application the error displaying again. the websocket logger is:

8/21/2018 4:43:42 PM|Warn |Logger.set_File:0|The current path to the log file has been changed to websocket.log. 8/21/2018 4:43:42 PM|Debug|WebSocket.sendHttpRequest:0|A request to the server: GET /signalr/connect?transport=webSockets&connectionToken=J4miXlCpKRgShrRbd8GK1au%2B6k7UYtBHV%2Fg2kRwG6iUh3yofmoKesO0Qm%2FwGnlfU700ieOENOeUEaGJOFYAQAFrS0lASreArieqM7XPOQmzeKIW4Dx2Rqc%2Fo05ZB9ztWcwWYErDRrlp30S0UNkDbxQ%3D%3D&connectionData=%5B%7B%22name%22%3A%22game%22%7D%5D&tid=8&authorization=Bearer%20eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiR3Vlc3RfMTAwNDkyIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9zZXJpYWxudW1iZXIiOiJhYjY2YzkyNi1kMzhmLTQzYzAtOTIxYS1kNTFiNjZkZDEyZDAiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjEwMDQ5MiIsIkFwcGxpY2F0aW9uVmVyc2lvbiI6IjEuMCIsIkRldmljZUlkIjoiYmI0MGU5NDU4YjY5ZTNjODU3ZTRhNzkzNTViNDFlNzEyZDg5NzdlMCIsIm5iZiI6MTUzNDg1MzY2MiwiZXhwIjoxNTM1MTEyODYyLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0LyIsImF1ZCI6IkFueSJ9.JYrsm48lwICMOMzY9MNwjgtBMGTPZcGbyrp-VwDBeJs HTTP/1.1 User-Agent: websocket-sharp/1.0 Host: artstorm.ir Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: c4g6LyAgEC9Z5loohIw5Vg== Sec-WebSocket-Version: 13 8/21/2018 4:43:42 PM|Debug|WebSocket.sendHttpRequest:0|A response to this request: HTTP/1.1 101 Switching Protocols Upgrade: websocket Server: Microsoft-IIS/10.0 X-Content-Type-Options: nosniff Sec-WebSocket-Accept: DL56iuslEBzQrI8///p+uZVwm/Y= Connection: Upgrade X-Powered-By: ASP.NET Date: Tue, 21 Aug 2018 12:14:22 GMT 8/21/2018 4:44:12 PM|Fatal|WebSocket.b176_2:0|WebSocketSharp.WebSocketException: The header of a frame cannot be read from the stream. at WebSocketSharp.WebSocketFrame.processHeader (System.Byte[] header) [0x00000] in :0 at WebSocketSharp.WebSocketFrame+<>c__DisplayClass73_0.b0 (System.Byte[] bytes) [0x00000] in :0 at WebSocketSharp.Ext+<>c__DisplayClass50_0.b__0 (IAsyncResult ar) [0x00000] in :0 8/21/2018 4:44:12 PM|Debug|WebSocket.closeHandshake:0|Was clean?: False sent: False received: False

RonWalker22 commented 5 years ago

Did you ever fix this?

salmanian commented 5 years ago

yes the problem was headers. websocket sometimes changes default headers so what we need to do is using SSL to encrypt headers

hjj28810 commented 5 years ago

how to fix this bug?

maikebing commented 4 years ago

how to fix this bug?

maikebing commented 4 years ago

356