sta / websocket-sharp

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

The header of a frame cannot be read from the stream ? #381

Open Elliot9 opened 7 years ago

Elliot9 commented 7 years ago

hi , my problem is when i sent a long String , the error happened like :|Fatal|<>c__DisplayClass17.<startReceiving>b__16|WebSocketSharp.WebSocketException: The header of a frame cannot be read from the stream. 於 WebSocketSharp.WebSocketFrame.processHeader(Byte[] header) 於 WebSocketSharp.WebSocketFrame.<>c__DisplayClassa.<readHeaderAsync>b__9(Byte[] bytes) 於 WebSocketSharp.Ext.<>c__DisplayClass9.<ReadBytesAsync>b__8(IAsyncResult ar) WebSocketSharp.CloseEventArgs And i found someone had the problem too like this so i wonder know ,how can i solve this problem and i try to set FragmentLength ,but i don't know how to do that my Application is a Winsform client include websocketsharp.dll(on Nuget version 1.0.3-rc11) and i try to sent long String to Stomp&SockJs Websocket Server BTW,Sending short String is work , and i found the max length i can sent (Encoding.GetEncoding("utf-8").GetBytes ) it's 16546 , Any ideas?

ReckerPeal commented 6 years ago

i got the same problem yet, have you resolve it ?

dthisner commented 5 years ago

Would love to get more information on this as well

Elliot9 commented 5 years ago

I remember that I have solved the problem. But it’s been too long. So I forgot the detail, maybe u have send the long string with length

dthisner commented 4 years ago

send it with length? somehow include the length/bit size in the request?

Elliot9 commented 4 years ago

like Me("content-length") = Content.Length.ToString()

dthisner commented 4 years ago

excuse me for my ignorance, not following how that would be added to my code.

In their example, where would you add it:


using WebSocketSharp;

namespace Example
{
  public class Program
  {
    public static void Main (string[] args)
    {
      using (var ws = new WebSocket ("ws://dragonsnest.far/Laputa")) {
        ws.OnMessage += (sender, e) =>
            Console.WriteLine ("Laputa says: " + e.Data);

        ws.Connect ();
        ws.Send ("BALUS");
        Console.ReadKey (true);
      }
    }
  }
}
No3371 commented 4 years ago

In the project I'm working on, a botclient will make and maintain a huge amount of WS connection to our server.

We use binary message only, and use 2 bytes in the message data as header. And there's a custom heartbeat message which is only 2 bytes per message, sent by the server every 10 seconds per clients.

It seems that if a process concurrently keeps too many connection, this error happens. (ex: 5000 is fine. Connections drops randomly when we tested with 10000)

p.s. Both server and the client process The CPU usage is not full.