GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sypbiz/SockJS.NET: A .NET implementation of the SockJS client

BranchesTags
Open more actions menu

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
server
server
 
 
syp.biz/SockJS.NET
syp.biz/SockJS.NET
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
syp.biz.SockJS.NET.pfx
syp.biz.SockJS.NET.pfx
 
 
syp.biz.SockJS.NET.sln
syp.biz.SockJS.NET.sln
 
 
syp.biz.SockJS.NET.sln.DotSettings
syp.biz.SockJS.NET.sln.DotSettings
 
 

Repository files navigation

SockJS.NET

An asynchronous .NET implementation of the SockJS client

Components

syp.biz.SockJS.NET.Common

Includes all interfaces, extensions, enums and utils which are common to the client, user of the client and for extending the client.

syp.biz.SockJS.NET.Client

The client library containing the actual SockJS client to be used by consuming applications.

syp.biz.SockJS.NET.Test

A test application which consumes the client library.

server

A node.js SockJS server to be used in conjunction with the test application.

Basic Usage

var sockJs = new SockJS("http://localhost:9999/echo");
sockJs.Connected += async (sender, e) =>
{
    // this event is triggered once the connection is established
    try
    {
        Console.WriteLine("Connected...");
        await sockJs.Send(JsonConvert.SerializeObject(new { foo = "bar" }));
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error: {e}");
    }
};

sockJs.Message += async (sender, msg) =>
{
    // this event is triggered every time a message is received
    try
    {
        Console.WriteLine($"Message: {msg}");
        await sockJs.Disconnect(); // disconnect after first received message
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error: {e}");
    }
};

sockJs.Disconnected += (sender, e) =>
{
    // this event is triggered when the connection is disconnected (for any reason)
    Console.WriteLine("Disconnected");
};

await sockJs.Connect(); // connect to the server

Advanced Usage

Customize Configuration

// create a default configuration file (default values)
var config = Configuration.Factory.BuildDefault("http://localhost:9999/echo"); 
var sockJs = new SockJs(config);

Customize Logger

config.Logger = new ConsoleLogger();

Customize Default Request Headers

config.DefaultHeaders = new WebHeaderCollection
{
    {HttpRequestHeader.UserAgent, "Custom User Agent"},
    {"application-key", "foo-bar"}
};

Customize Transports

// add custom transport implementations
config.TransportFactories.Add(new CustomTransportFactory());

// remove custom/built-in transport implementation
config.TransportFactories.Remove(config.TransportFactories.First(t => t.Name == "websocket-system"));

// disable transport
config.TransportFactories.First(t => t.Name == "websocket-system").Enabled = false;

Note

Built-in WebSocket connection (websocket-system) 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 based on the SockJS-client JavaScript library (license).

Dependencies

  • Newtonsoft.Json (license)

About

A .NET implementation of the SockJS client

Resources

Readme
MIT license
Activity
Custom properties

Stars

20 stars

Watchers

2 watching

Forks

16 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.