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?

wonea
  • 4,783
  • 17
  • 86
  • 139
Dickens A S
  • 3,824
  • 2
  • 22
  • 45

1 Answers1

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");
Dickens A S
  • 3,824
  • 2
  • 22
  • 45
  • @ZigmaEmpire can you explain or give a pointer where this is explained please? – fbenoit Jan 12 '16 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 – Dickens A S Jan 13 '16 at 05:24