WebSocket server troubles

  • Thread starter Thread starter da.3vil.coder
  • Start date Start date
D

da.3vil.coder

Guest
I am trying to implement a WebSocket server in C#. I have the handshake up and running and have been working on the decoding of the message, which is where I've been running into a brick wall. Right now I'm sending small messages, literally 123, so I know the message length won't exceed 125; knowing that, the mask will be bytes with the indexes of 2 - 5 and the message will start at index 6. So, I have the following code:

var maskingKey = new byte[4] { buffer[2], buffer[3], buffer[4], buffer[5] };

var decoded = new byte[payloadLength];
for (int i = 0; i < payloadLength; i++)
decoded = (byte)(buffer[6 + i] ^ maskingKey[i % 4]);
Console.WriteLine(Encoding.UTF8.GetString(decoded));


Where I was expecting to see my message of 123 (in my example), I'm getting 242.

My client side code isn't anything special, basic JavaScript

websocket = new WebSocket( "ws://127.0.0.1:55452/");
websocket.send('123');


The client code is running in the latest version of Firefox.

I'm really baffled by why this isn't working. Especially after finding multiple examples of other people having the exact same thing and saying it work. Any help on this would be greatly appreciated.

Thanks in advance.

Continue reading...
 
Back
Top