Skip to content

A .NET implementation of the SockJS client

License

Notifications You must be signed in to change notification settings

CachePeng/SockJS.NET

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SockJS.NET

A .NET implementation of the SockJS client

Componenets

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.

Basic Usage

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");
});

Note

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.

References

This library is a .NET port of the SockJS Client JavaScript library and is subject to the same license published here, via commit cc6ae9531bda2d4ee80e52fab246933558790163

About

A .NET implementation of the SockJS client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 95.9%
  • HTML 2.5%
  • JavaScript 1.6%