连接基于node.js的socket.. io WebSocket服务器从c#程序

本文关键字:服务器 WebSocket 程序 io socket node js 连接 | 更新日期: 2023-09-27 18:04:21

我需要从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 WebSocket服务器从c#程序

Node.JS socket。io库使用不同的URL模式,但你已经给了根URL,请更改你的URL如下,然后它应该工作

WebSocket webSocketClient = new WebSocket("ws://localhost:8080/socket.io/?EIO=3&transport=websocket");