doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
721 stars 124 forks source link

Client initialization , socket.io namespaces #310

Open Mobinkarimi1 opened 1 year ago

Mobinkarimi1 commented 1 year ago

` public SocketIOUnity socket;

void Start() { var uri = new Uri("http://192.168.1.5:11100"); socket = new SocketIOUnity(uri, new SocketIOOptions { Transport = SocketIOClient.Transport.TransportProtocol.WebSocket }); socket.JsonSerializer = new NewtonsoftJsonSerializer();

    socket.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    socket.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };

    socket.Connect();

    var nsp = socket("/my-namespace");

}

`

The initialization of namespaces in the client cannot be done and an error occurs, please help You can do this by creating a new connection, but it's silly (you have to create a new connection for each namespace!)

` public SocketIOUnity socket; public SocketIOUnity nsp;

void Start()
{
    var uri = new Uri("http://192.168.1.5:11100");
    socket = new SocketIOUnity(uri, new SocketIOOptions
    {
        Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
    });
    socket.JsonSerializer = new NewtonsoftJsonSerializer();

    socket.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    socket.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };

    socket.Connect();

    nsp = new SocketIOUnity("http://192.168.1.5:11100/my-namespace", new SocketIOOptions
    { });

    nsp.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    nsp.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };
    nsp.Connect();

}

` How to do this without creating a new connection?

Mobinkarimi1 commented 1 year ago

` public SocketIOUnity socket;

void Start() { var uri = new Uri("http://192.168.1.5:11100"); socket = new SocketIOUnity(uri, new SocketIOOptions { Transport = SocketIOClient.Transport.TransportProtocol.WebSocket }); socket.JsonSerializer = new NewtonsoftJsonSerializer();

    socket.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    socket.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };

    socket.Connect();

    var nsp = socket("/my-namespace");

}

`

The initialization of namespaces in the client cannot be done and an error occurs, please help You can do this by creating a new connection, but it's silly (you have to create a new connection for each namespace!)

` public SocketIOUnity socket; public SocketIOUnity nsp;

void Start()
{
    var uri = new Uri("http://192.168.1.5:11100");
    socket = new SocketIOUnity(uri, new SocketIOOptions
    {
        Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
    });
    socket.JsonSerializer = new NewtonsoftJsonSerializer();

    socket.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    socket.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };

    socket.Connect();

    nsp = new SocketIOUnity("http://192.168.1.5:11100/my-namespace", new SocketIOOptions
    { });

    nsp.OnConnected += (sender, e) =>
    {
        Debug.Print("socket.OnConnected");
    };

    nsp.OnDisconnected += (sender, e) =>
    {
        Debug.Print("disconnect: " + e);
    };
    nsp.Connect();

}

` How to do this without creating a new connection?

io.in(my-namespace).emit("start game"); Apparently this solution is suitable, do you know how to use it in C#?

doghappy commented 1 year ago

No, you can't: https://stackoverflow.com/a/48037918