Problems with C# and UTF-16

Asked

Viewed 26 times

0

the scenario is this... I am exchanging data with a websocket, however, one of the messages I send no reply.

The message contains the following " X02 x00" but when compiling turns to " u0002 0".

It seems that the websocket does not understand this coding, it is possible this?

Follow the full code:

    private static void WsData_MessageReceived(object sender, MessageReceivedEventArgs e)
    {
        var msg = e.Message;

        Form1.Log("Mensagem Data Recebida: " + msg);

        if (msg.StartsWith("100"))
        {
            Thread.Sleep(200);
            EnviarMsg("\x16\x00" + "CONFIG_33_0,OVInPlay_33_0\x01", "data");               
        }
        else if (msg.Substring(1,6) == "__time")
        {
            EnviarMsg("\x02\x00" + "command\x01nst\x01" + authToken + "\x02SPTBK", "data");
        }

        if (msg.Contains("AD"))
        {
            if (msg.Contains("CONFIG_"))
            {

            }
        }
       
    }

The message sending code:

    public static void EnviarMsg(string msg, string data)
    {
        var sckt = socketData;
        if (data == "handshake") { sckt = socketHandshake; }

        if (sckt.State == WebSocket4Net.WebSocketState.Open)
        {
            
            sckt.Send(msg);
            Mensagens.Add(msg);
            Form1.Log("Mensagem Enviada: (" + data.ToString() + ")" + msg);
        }
        else
        {

        }
    }

It is worth mentioning that, the same algorithm in python works... due to b' before the string causing str to be read as byte, am I right? I’ve already exhausted my attempts to get something related, can give me a light?

  • Hello Sloan. Again, please read the links, they will help you get the help you need. It’s important you [Edit] and add a [mcve] of the problem (this is the most important part), ie, a simple code, mainly that we can execute without difficulty, just copying and pasting to test somewhere, follow the instructions of the link. To better enjoy the site, understand and avoid closures is worth reading the Stack Overflow Survival Guide in English. Thank you for understanding.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.