Communicating with a socket.io server via c#

There is a project on codeplex ( NuGet as well ) that is a C# client for socket.io. (I am the author of this project - so I'm biased) I couldn't find exactly what I needed in a client, so I built it and released it back into the open.

Example client style:

socket.On("news", (data) =>    {
Console.WriteLine(data);
});

Use the following library: https://github.com/sta/websocket-sharp It is available via NuGet:

PM> Install-Package WebSocketSharp -Pre

To connect to a Socket.IO 1.0 + server, use the following syntax:

using (var ws = new WebSocket("ws://127.0.0.1:1337/socket.io/?EIO=2&transport=websocket"))
{
    ws.OnMessage += (sender, e) =>
      Console.WriteLine("New message from controller: " + e.Data);

    ws.Connect();
    Console.ReadKey(true);
}

In other words, append this to the localhost:port - "socket.io/?EIO=2&transport=websocket".

My full server code: https://gist.github.com/anonymous/574133a15f7faf39fdb5


Well, I found another .Net library which works great with socket.io. It is the most updated too. Follow the below link,

Quobject/SocketIoClientDotNet

using Quobject.SocketIoClientDotNet.Client;

var socket = IO.Socket("http://localhost");
socket.On(Socket.EVENT_CONNECT, () =>
{
    socket.Emit("hi");
});

socket.On("hi", (data) =>
{
    Console.WriteLine(data);
    socket.Disconnect();
});
Console.ReadLine();

Hope, it helps someone.