Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets-Sharp Exeption: WebSocketException [closed]

I made a xamarin iOS/Android Application. This App use websockets-sharp for the comunication with the server.

Now after connecting i got the following error:

03-29 16:11:14.999 I/mono-stdout(19865): 29.03.2018 16:11:14|Fatal|<>c__DisplayClass17.<startReceiving>b__16|WebSocketSharp.WebSocketException: The header of a frame cannot be read from the stream.
29.03.2018 16:11:14|Fatal|<>c__DisplayClass17.<startReceiving>b__16|WebSocketSharp.WebSocketException: The header of a frame cannot be read from the stream.
03-29 16:11:15.005 I/mono-stdout(19865):                             at WebSocketSharp.WebSocketFrame.processHeader (System.Byte[] header) [0x00017] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
                            at WebSocketSharp.WebSocketFrame.processHeader (System.Byte[] header) [0x00017] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
                            at WebSocketSharp.WebSocketFrame+<>c__DisplayClassa.<readHeaderAsync>b__9 (System.Byte[] bytes) [0x00000] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
                            at WebSocketSharp.Ext+<>c__DisplayClass9.<ReadBytesAsync>b__8 (System.IAsyncResult ar) [0x000a2] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
03-29 16:11:15.005 I/mono-stdout(19865):                             at WebSocketSharp.WebSocketFrame+<>c__DisplayClassa.<readHeaderAsync>b__9 (System.Byte[] bytes) [0x00000] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
03-29 16:11:15.006 I/mono-stdout(19865):                             at WebSocketSharp.Ext+<>c__DisplayClass9.<ReadBytesAsync>b__8 (System.IAsyncResult ar) [0x000a2] in <38d3cef14c5a4fc9a92de0991034bc1a>:0 
[0:] Socket is disconected...

Does someone else got this error too and know how to solve this?

like image 306
DerStarkeBaer Avatar asked Mar 29 '18 14:03

DerStarkeBaer


2 Answers

Its not the code that is causing error its the mess created by algorithm you have written for the application. The actual error is "The header of a frame cannot be read from the stream" this simply can be caused due to the following issues

Your appliation and server both are sending bulk messages or heavy data at faster rate at the same time to each other. which is well defined and explained here

Solution

You have to optimize your algorithm to meet the following constraints and remove that error

  1. Monitor and Control the data transfer rate to/from the server
  2. Try to wait for the completion of data transfer of one side (Half Duplex)
like image 163
Zain Ul Abidin Avatar answered Oct 19 '22 00:10

Zain Ul Abidin


Sorry, the problem was in my code...

If you send an event that doesn't exist on the server, this error occures. You can only send events that exists, otherwise it will fail.

like image 39
DerStarkeBaer Avatar answered Oct 19 '22 00:10

DerStarkeBaer