3

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?

1 Answer 1

10

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");
2
  • @ZigmaEmpire can you explain or give a pointer where this is explained please?
    – fbenoit
    Jan 12, 2016 at 21:54
  • The URL is identified by practically executing the socket.io javascript client on a chrome browser and watching the network traffic screen provided by google chrome browser, there is no proper documentation for this Jan 13, 2016 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.