weixin_39823017
weixin_39823017
2021-01-10 03:12

"Header part of a frame cannot be read" when using Google Chrome

I am able to connect to my Websocket-Sharp server just fine with Firefox Version 28.0, but as soon as I try to connect using Google Chrome Version 34.0.1847.131 m, I get the following error:


27.04.2014 13:13:27|Fatal|WebSocket.acceptException|WebSocketSharp.WebSocketException: The header part of a frame cannot be read from the data source.
                             bei WebSocketSharp.WsFrame.<>c__DisplayClasse.<parseasync>b__d(Byte[] header)
                             bei WebSocketSharp.Ext.<>c__DisplayClass6.<readbytesasync>b__5(IAsyncResult ar)
</readbytesasync></parseasync>

The error appears both when using the NuGet version and a self compiled version directly taking from Github (latest commit 16f5c03b95).

Server initialization code:

 C#
int port = 7777;
Log.Info("Starting server socket at port " + port + "...");
this.WebSocketServer = new WebSocketSharp.Server.WebSocketServer(port);
this.WebSocketServer.AddWebSocketService<gamewebservice>("/game");
// TODO: Register additional services
this.WebSocketServer.Start();
</gamewebservice>

Service code:

 C#
    internal sealed class GameWebService : WebSocketSharp.Server.WebSocketService
    {
        private static log4net.ILog Log = log4net.LogManager.GetLogger(typeof(GameWebService));

        protected override void OnOpen()
        {
            Log.Info("Open");
        }

        protected override void OnClose(WebSocketSharp.CloseEventArgs e)
        {
            Log.Info("Closed");
        }

        protected override void OnError(WebSocketSharp.ErrorEventArgs e)
        {
            Log.Error(e.Message);
        }

        protected override void OnMessage(WebSocketSharp.MessageEventArgs e)
        {
            Log.Info(e.Data);
        }
    }

Client connect:

 JavaScript
var serverUrl = 'ws://myserveraddress:7777/game';
self.connection = new WebSocket(serverUrl, ['soap']);
self.connection.onerror = self.handleConnectionError;
self.connection.onmessage = self.handleConnectionMessage;
self.connection.onopen = self.handleConnectionOpen;
self.connection.onclose = self.handleConnectionClose;

The log shows the "Open" entry logged in the OnOpen method. Then the error occurs.

The client side JavaScript has a method attached to the onopen event, but does not yet send any messages (e.g. the method is empty).

The website and server are not using SSL. The error happens when connectin locally or via a remote machine over the internet.

The server uses .NET 4.5

该提问来源于开源项目:sta/websocket-sharp

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

16条回答