doghappy / socket.io-client-csharp

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

EmitAsync doesn't seem to work with data parameters #349

Closed deleojur closed 6 months ago

deleojur commented 6 months ago

I have a connection with a Node.JS server. Sending empty messages works fine. receiving messages from the server also works fine. However, when I try to send some additional data with the EmitAsync function, it does not register anything. There is no exception thrown or anything of this nature; the server just does not receive a message.

This is my code::

public void SendDataPacket(DataPacket dataPacket)
{
    //if the client is connected, send the dataPacket. If not, add it to the queue to be sent at a later time.
    if (client.Connected)
    {
        string data = dataPacket.ToJson();
        byte[] bytes = Encoding.ASCII.GetBytes(data);

        //None of these calls are registered on the server side.
        client.EmitAsync(dataPacket.EventName, bytes);
        client.EmitAsync(dataPacket.EventName, data);
        client.EmitAsync(dataPacket.EventName, dataPacket);

        //This works fine.
        client.EmitAsync(dataPacket.EventName);
    } else
    {
        dataPackets.Enqueue(dataPacket);
    }
}

I already checked that the object in question can be serialized. Sending an empty string also does not work.

On the back end side, this is my Javascript code

socket.on('request received', (request) => {
  console.log('some request received', request); 
});

Debugging either instance does not resolve in any meaningful errors or other casuses for this problem. Any help is greatly appreciated.

deleojur commented 6 months ago

Updating to version 3.1.1 seems to resolve this issue, but leads to issue #350.