【问题标题】:WebSockets-Sharp Exeption: WebSocketException [closed]WebSockets-Sharp Exeption:WebSocketException [关闭]
【发布时间】:2018-09-08 13:17:10
【问题描述】:

我制作了一个 xamarin iOS/Android 应用程序。 此应用程序使用websockets-sharp 与服务器进行通信。

现在连接后出现以下错误:

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...

其他人是否也遇到此错误并且知道如何解决此问题?

【问题讨论】:

    标签: c# xamarin exception mono websocket-sharp


    【解决方案1】:

    导致错误的不是代码,而是您为应用程序编写的算法造成的混乱。 实际的错误是“无法从流中读取帧的标题”,这可能是由于以下问题引起的

    您的应用程序和服务器都在同时以更快的速度向对方发送批量消息或大量数据。这是很好的定义和解释here

    解决方案

    您必须优化您的算法以满足以下约束并消除该错误

    1. 监控与服务器之间的数据传输速率
    2. 尝试等待一侧数据传输完成(半双工)

    【讨论】:

      【解决方案2】:

      抱歉,问题出在我的代码中...

      如果您发送服务器上不存在的事件,则会发生此错误。 只能发送存在的事件,否则会失败。

      【讨论】:

        猜你喜欢
        • 2016-07-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-25
        • 1970-01-01
        • 2014-11-24
        相关资源
        最近更新 更多