简体   繁体   English

Websocket 与 C# 客户端和 Node.js 服务器握手

[英]Websocket Closing Handshake with a C# client and a Node.js server

I use "CloseOutputAsync" on the C# client to initiate the close handshake with the Node.js server.我在 C# 客户端上使用“CloseOutputAsync”来启动与 Node.js 服务器的关闭握手。

My Node.js server receives a "close" event and immediately sets his "websocket.readyState" as "CLOSED" without going through "CLOSING".我的 Node.js 服务器收到“关闭”事件并立即将他的“websocket.readyState”设置为“关闭”,而无需通过“关闭”。

As my C# client is sending the close handshake, he sets his state as "CloseSent".当我的 C# 客户端发送关闭握手时,他将他的 state 设置为“CloseSent”。

The problem is that my C# stays in this state, while my Node.js server believes that the websocket connection is closed.问题是我的 C# 停留在这个 state 中,而我的 Node.js 服务器认为 ZBF56D570E62CDB5713186 连接是关闭的

How can I detect that the connection is "CLOSING" on the server and what function of the ws library can I use to send an acknoledgment to the C# client to make sure that his state goes from "CloseSent" to "Closed"?我如何检测该连接在服务器上“关闭”,以及WS库的ZC1C1C425268E68385D1AB5074C174F14F14Z我可以使用ZD7EFA19FBE7D3972FD55ADB602223D73D74EN ZCELT to MAKE ACKNOLEDEND,即

I am using the standard "ws" library under Node.js and the standard "System.Net.WebSockets" under C#.我正在使用 Node.js 下的标准“ws”库和 C# 下的标准“System.Net.WebSockets”。

I finally found the solution.我终于找到了解决方案。

When the C# client is initiating the close, he should send a close with "CloseAsync" instead of "CloseOutputAsync".当 C# 客户端启动关闭时,他应该使用“CloseAsync”而不是“CloseOutputAsync”发送关闭。 The node.js server immediatly sets the websocket state as "Closed" without going through "Closing" state (is never found a way to trigger this "Closing" state) but then the C# client sets his state as "Closed". The node.js server immediatly sets the websocket state as "Closed" without going through "Closing" state (is never found a way to trigger this "Closing" state) but then the C# client sets his state as "Closed".

If the node.js server is initiating the close, then the C# client should use "CloseOutputAsync".如果 node.js 服务器正在启动关闭,则 C# 客户端应使用“CloseOutputAsync”。 The C# client states goes from Open -> CloseReceived -> CloseSent -> Closed. C# 客户端状态为打开 -> CloseReceived -> CloseSent -> Closed。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM