Team XSockets.NET

Multiplexing

One fundamental thing to understand about controllers is that you can multiplex over several controllers on a single connection. This makes it much easier to split your logic into separate controllers.

We will once again use Putty, this time to see how we can multiplex over 2 controllers.

Add two simple controllers

Create two controller and override the OnMessage method. We do not need any custom methods to show multiplexing.

Inside the OnMessage we will write to the IXLogger to be able to see what controller we called.

using System.Threading.Tasks;
using XSockets.Core.Common.Socket.Event.Interface;
using XSockets.Core.Common.Utility.Logging;
using XSockets.Core.XSocket;
using XSockets.Core.XSocket.Helpers;
using XSockets.Plugin.Framework;

namespace XSocketsTutorial
{
    public class Foo : XSocketController
    {
        public override async Task OnMessage(IMessage message)
        {
            Composable.GetExport<IXLogger>().Information("Foo - OnMessage {@m}", message);
            await this.InvokeToAll(message);
        }
    }

    public class Bar : XSocketController
    {
        public override async Task OnMessage(IMessage message)
        {
            Composable.GetExport<IXLogger>().Information("Bar - OnMessage {@m}", message);
            await this.InvokeToAll(message);
        }
    }
}

Connect with Putty

We send the handshake as usual, and then send the Init commands for both the controller foo and bar.

You can see that both controllers send a open message with the reserved topic of 2.

You can also notice that the PersistenId is identical on both controllers, but the ControllerId is unique for each controller.

multiplexing 1

Send messages

We can now target each controller individually over a single socket connection. We are logging the incoming data in each of the controllers so that we can see what controller we actually invoked.

First we call the foo controller, and then the bar controller

Putty:

putty multiplexing

Server Log:

multiplexing log

results matching ""

    No results matching ""