State is the key to success - XSockets/XSockets.NET-4.0 GitHub Wiki

##State is the key to success State is the most important thing in full-duplex real-time applications. Without state you will not know where to send messages, and you will spend a lot of more time to implement business logic in your applications

How to use state on the server

All public getters and setters are accessible from the client API, so you can actually get and set the Controller properties from the client API's.

Below you can see that the chat example is extended with a property for username. Since we can use state to know who the user is at all times there is no need passing the unnecessary data with every message.

Server Controller with state

//using XSockets.Core.XSocket;
//using XSockets.Core.XSocket.Helpers;

public class Chat : XSocketController
{
    public string UserName {get;set;}
    
    public void ChatMessage(string message)
    {
        this.InvokeToAll(new {UserName = this.UserName, Text = message},"chatmessage");
    }
}

Set the UserName from the client API's

Client - JavaScript

conn.controller('chat').setProperty('username','Espen Knutsen');

Client - C#

conn.Controller("chat").SetProperty("username","Espen Knutsen");

So to repeat... Since we at all times know the username there is no need for passing it to the server when we can attach the user on the message going out.