我需要从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 回调始终触发,有人可以帮忙吗?
答案 0 :(得分:7)
Node.JS socket.io库使用不同的URL模式但您已经提供了根URL,请按照以下方式更改您的URL,然后它应该可以工作
WebSocket webSocketClient = new WebSocket("ws://localhost:8080/socket.io/?EIO=3&transport=websocket");