从 C# 程序连接基于 node.js socket.io WebSocket 服务器
Connect node.js based socket.io WebSocket server from a C# program
我需要从 C# windows 表单代码连接基于 Node.js 的 WebSocket
使用的节点模块https://github.com/Automattic/socket.io
我正在使用 superwebsocket 和 WebSocket4Net
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperWebSocket;
using SuperWebSocket.SubProtocol;
using WebSocket4Net;
......
......
WebSocket webSocketClient = new WebSocket("ws://localhost:8080/");
webSocketClient.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocketClient_Error);
webSocketClient.AllowUnstrustedCertificate = true;
webSocketClient.Opened += new EventHandler(webSocketClient_Opened);
webSocketClient.Closed += new EventHandler(webSocketClient_Closed);
webSocketClient.MessageReceived += new EventHandler<MessageReceivedEventArgs>(webSocketClient_MessageReceived);
webSocketClient.Open();
但是只有webSocketClient_Error回调总是触发,有人能帮忙吗?
Node.JS socket.io 库使用了不同的 URL 模式,但是你给了 root URL,请如下更改你的 URL 然后它应该可以工作
WebSocket webSocketClient = new WebSocket("ws://localhost:8080/socket.io/?EIO=3&transport=websocket");
我需要从 C# windows 表单代码连接基于 Node.js 的 WebSocket
使用的节点模块https://github.com/Automattic/socket.io
我正在使用 superwebsocket 和 WebSocket4Net
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
using SuperWebSocket;
using SuperWebSocket.SubProtocol;
using WebSocket4Net;
......
......
WebSocket webSocketClient = new WebSocket("ws://localhost:8080/");
webSocketClient.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(webSocketClient_Error);
webSocketClient.AllowUnstrustedCertificate = true;
webSocketClient.Opened += new EventHandler(webSocketClient_Opened);
webSocketClient.Closed += new EventHandler(webSocketClient_Closed);
webSocketClient.MessageReceived += new EventHandler<MessageReceivedEventArgs>(webSocketClient_MessageReceived);
webSocketClient.Open();
但是只有webSocketClient_Error回调总是触发,有人能帮忙吗?
Node.JS socket.io 库使用了不同的 URL 模式,但是你给了 root URL,请如下更改你的 URL 然后它应该可以工作
WebSocket webSocketClient = new WebSocket("ws://localhost:8080/socket.io/?EIO=3&transport=websocket");