c# - WebSockets-尖锐异常: WebSocketException

标签 c# xamarin exception mono websocket-sharp

<分区>

我制作了一个 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...

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

最佳答案

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

您的应用程序和服务器同时以更快的速度相互发送大量消息或大量数据。这是明确定义和解释here

解决方案

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

  1. 监视和控制进出服务器的数据传输速率
  2. 尝试等待一侧(半双工)数据传输完成

关于c# - WebSockets-尖锐异常: WebSocketException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49558475/

相关文章:

c# - WindowsPrincipal.IsInRole 不适用于 IIS 7/Windows Server 2K8,但适用于 IIS 6/Win Server 2K3

java - 无法捕获 Spring MVC 中的 org.hibernate.util.JDBCExceptionReporter 异常

android - 从错误的线程异常调用

android - Android 上的 jNetPcap : problem with findAllDevs method!

xamarin - 如果用户按 xamarin 表单中的硬件后退按钮,如何取消订阅 MessagingCenter?

c# - OSMSharp - 获取有关实际道路的信息

c# - IFormFile 未从程序集 'Microsoft.AspNetCore.Http 3.0' 加载类型 Microsoft.AspNetCore.Http.Internal.FormFile'

c#.net 网络服务

c# - 我可以使用 C# 在数据集的中间添加一行吗?

xamarin.ios - 无法从 "Microsoft.Win32.RegistryKey"解析 "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"引用 (MT2002)