M
M
mada2017-12-08 13:08:59
C++ / C#
mada, 2017-12-08 13:08:59

How to connect to server via Socket.IO in C#?

There is a need to transfer this code to C #

var socket = io("socket.donationalerts.ru:3001");
    socket.emit('add-user', {token: "my-token", type: "minor"});
    socket.on('donation', function(msg){
        console.log(msg);
});

This is where the response in jsone comes in.
I am making a test console application to understand what goes where and how:
Connected SocketIoClientDotNet .
var socket = IO.Socket("http://socket.donationalerts.ru:3001/");

socket.On(Socket.EVENT_CONNECT, () => {
    socket.Emit("donation");
});

socket.On("donation", (data) =>
{
    Console.WriteLine(data.ToString());
    socket.Disconnect();
});
Console.ReadLine();

This code outputs to the console
DoWrite data = System.Byte[]
Well, and there are no add-user parameters in it. Actually the question can someone tell me how to transfer them there. And in general, in which direction to dig, I will be very grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Evseev, 2017-12-14
@mada

I believe in C# just a low-level response comes - an array of bytes.
It must be converted to a string:
var str = Encoding.UTF8.GetString(data);
https://msdn.microsoft.com/en-us/library/744y86tc(...
Only you would like to know what encoding is used. I assumed UTF-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question