从 C# 程序连接基于 node.js 的 socket.io WebSocket 服务器 [英] Connect node.js based socket.io WebSocket server from a C# program

查看:85
本文介绍了从 C# 程序连接基于 node.js 的 socket.io WebSocket 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 C# windows 窗体代码连接基于 Node.js 的 WebSocket

I need to connect Node.js based WebSocket from a C# windows form code

使用的节点模块https://github.com/Automattic/socket.io

我正在使用 superwebsocket 和 WebSocket4Net

I am using superwebsocket and 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 回调总是触发,有人可以帮忙吗?

But only webSocketClient_Error callback triggers always, can anyone help?

推荐答案

Node.JS socket.io 库使用不同的 URL 模式,但您已提供根 URL,请按如下方式更改您的 URL,然后它应该可以工作

Node.JS socket.io library uses a different URL pattern but you have given root URL, Please change your URL as follows then it should work

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

这篇关于从 C# 程序连接基于 node.js 的 socket.io WebSocket 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆