I am currently trying to feed my socket.io server with data from my C# client. But I am not sure how to receive the message on the server.
My server code:
const io = require('socket.io')(9000);
io.on('connection', (socket) => {
console.log('Connected');
}
First of all I don't know which event I have to listen to, but nevertheless I am unable to send data to my server using the following client (which uses Websocket-sharp) code:
private void init()
{
// start socket connection
using (var ws = new WebSocket("ws://localhost:9000/socket.io/?EIO=2&transport=websocket"))
{
ws.OnMessage += (sender, e) =>
API.consoleOutput("Message: " + e.Data);
ws.OnError += (sender, e) =>
API.consoleOutput("Error: " + e.Message);
ws.Connect();
ws.Send("server");
}
}
The connection works, but how do I receive the message of the server? The sending does not fire an error, therefore I think it does work.
socket.iodoesn't useswebsocketprotocol exactly. So,c#websocketclient can't communicate withnode.jssocket.ioserver. Probably, you can try github.com/Quobject/SocketIoClientDotNet forc#socket.ioclient.SocketIoClientDotNet, but I can say for sure thatwebsocket-sharpcan't be directly used to communicate withsocket.ioserver. github.com/sta/websocket-sharp/issues/81#issuecomment-104650660SocketIoClientDotNetkeeps reconnecting and does not fire the localSocket.EVENT_CONNECTevent. Seems to be not working either.