T
T
TheTalion2016-09-30 20:38:23
C++ / C#
TheTalion, 2016-09-30 20:38:23

WebSocket: how to convert byte to string when receiving?

I send the following message to the websocket server (from the client):

На C#
int test1 = 30;
int test2 = 40;
byte[] data = new byte[8];
        
byte[] testB1 = System.BitConverter.GetBytes(test1);
byte[] testB2 = System.BitConverter.GetBytes(test2);
        
testB1.CopyTo(data,0);
testB2.CopyTo(data,4);
        
webSocket.Send(data);

How can I decode it back from byte to string on the server (so that the pre-sent numbers come out)?
Пробовал вот так, но выдает какую-то ерунду, а не мои цифры 
string result = Encoding.UTF8.GetString(data); 
А вот так:
string result = BitConverter.ToString(data);
выдает хекс, но как его перевести в мои цифры не знаю.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question