You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A node.js SockJS server to be used in conjunction with the test application.
Basic Usage
varsockJs=newSockJS("https://localhost:9999/echo");sockJs.Connected+=async(sender,e)=>{// this event is triggered once the connection is establishedtry{Console.WriteLine("Connected...");awaitsockJs.Send(JsonConvert.SerializeObject(new{foo="bar"}));}catch(Exceptionex){Console.WriteLine($"Error: {e}");}};sockJs.Message+=async(sender,msg)=>{// this event is triggered every time a message is receivedtry{Console.WriteLine($"Message: {msg}");awaitsockJs.Disconnect();// disconnect after first received message}catch(Exceptionex){Console.WriteLine($"Error: {e}");}};sockJs.Disconnected+=(sender,e)=>{// this event is triggered when the connection is disconnected (for any reason)Console.WriteLine("Disconnected");};awaitsockJs.Connect();// connect to the server
Advanced Usage
Customize Configuration
// create a default configuration file (default values)varconfig=Configuration.Factory.BuildDefault("https://localhost:9999/echo");varsockJs=newSockJs(config);
Customize Logger
config.Logger=newConsoleLogger();
Customize Default Request Headers
config.DefaultHeaders=newWebHeaderCollection{{HttpRequestHeader.UserAgent,"Custom User Agent"},{"application-key","foo-bar"}};
Customize Transports
// add custom transport implementationsconfig.TransportFactories.Add(newCustomTransportFactory());// remove custom/built-in transport implementationconfig.TransportFactories.Remove(config.TransportFactories.First(t =>t.Name=="websocket-system"));// disable transportconfig.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.