Team XSockets.NET

Lifetime Events

How to handle connection lifetime events

The events on connection level provide information about the socket being opened/closed. The controllers has their own lifetime events.

OnConnected

conn.OnConnected += (sender, eventArgs) => Console.WriteLine("Connected");
conn.Open();

OnDisconnected

conn.OnDisconnected += (sender, eventArgs) => Console.WriteLine("Disconnected");
conn.Open();

How to handle controller lifetime events

The controller has nothing to do with the actual socket. These events tell you about the controllers you are using over your connection.

OnOpen

conn.Controller("chat").OnOpen += (sender, connectArgs) => {
    Console.WriteLine("Opened");
};

OnClose

conn.Controller("chat").OnClose += (sender, disconnectArgs) =>{
    Console.WriteLine("Closed");
};

Open a controller

As soon as you start to communicate over a new controller the OnOpen event will fire. You actually do not need to specify the controller in the connection. As long as the controller exists on the server the OnOpen event will fire.

Close a controller

To close as controller (not the actual connection/socket) you just call the Close method on the controller instance. This will fire the OnClose event on the controller.

conn.Controller("chat").Close();

OnOpen

conn.Controller("chat").OnOpen += (sender, connectArgs) => {
    Console.WriteLine("Open {0}", connectArgs.ClientInfo.Controller);
};

OnClose

conn.Controller("chat").OnClose += (sender, disconnectArgs) => {
    Console.WriteLine("Closed {0}", disconnectArgs.ClientInfo.Controller);
};

results matching ""

    No results matching ""