A .NET implementation of the SockJS client
Includes all interfaces, extensions, enums and utils which are common to the client, user of the client and for extending the client.
The client library containing the actual SockJS client to be used by consuming applications.
A test application which consumes the client library.
A node.js SockJS server to be used in conjunction with the test application.
SockJS.SetLogger(new ConsoleLogger()); // sets the global logger
var sockJs = new SockJS("http://localhost:9999/echo"); // creates a client and points it to the local node.js server
sockJs.AddEventListener("open", (sender, e) =>
{
Console.WriteLine("Connection opened");
sockJs.Send("foo");
});
sockJs.AddEventListener("message", (sender, e) =>
{
var stringifiedArgs = string.Join(",", e.Select(o => o?.ToString() ?? null));
Console.WriteLine($"Message received: {stringifiedArgs}");
if (e[0] is TransportMessageEvent msg)
{
var dataString = msg.Data?.ToString();
Console.WriteLine($"Message received: Data = {dataString}");
if (dataString == "foo")
{
Console.WriteLine("Echo successful -> closing connection");
sockJs.Close();
}
}
});
sockJs.AddEventListener("close", (sender, e) =>
{
Console.WriteLine("Connection closed");
});
WebSocket connection is implemented via System.Net.WebSockets.ClientWebSocket and as such, is not supported on Windows 7, Windows Vista SP2, and Windows Server 2008. See Remarks section.
This library is a .NET port of the SockJS Client JavaScript library and is subject to the same license published here, via commit cc6ae9531bda2d4ee80e52fab246933558790163