Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect node.js based socket.io WebSocket server from a C# program

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

Node module used https://github.com/Automattic/socket.io

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();

But only webSocketClient_Error callback triggers always, can anyone help?

like image 942
Dickens A S Avatar asked Aug 24 '26 14:08

Dickens A S


1 Answers

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");
like image 103
Dickens A S Avatar answered Aug 26 '26 02:08

Dickens A S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!