1

我正在使用普通的 C# await httpListenerContext.AcceptWebSocketAsync(subProtocol: null),一切似乎都很好,并且正在从 Chrome 成功发送和传输数据,但是有时连接似乎无缘无故地断开,或者客户端将部分发送数据,这尤其令人讨厌,因为数据是 JSON,我只会得到一半的对象(我确定我会在客户端完整发送它)

我正在 localhost 上进行测试,因此不可能出现任何连接问题(不是因为 TCP 而出现的问题)

我看到我有时会收到以下异常:

Error while processing account:The 'System.Net.Web
Sockets.ServerWebSocket' instance cannot be used for communication because it ha
s been transitioned into the 'Aborted' state.:System.Net.WebSockets.WebSocketExc
eption (0x80004005): The 'System.Net.WebSockets.ServerWebSocket' instance cannot
 be used for communication because it has been transitioned into the 'Aborted' s
tate. ---> System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Net.WebSockets.WebSocketHttpListenerDuplexStream.<ReadAsyncCore>d__
4

0 回答 0