0

Hei Guys,

i'm building my own websocket server, to learn something.

Now i currently have a java socket server which establishes successful with my client but when i send with my client "test", i receive something like "?„þdl»ŠÏ". It is always a different receive.

There is no line end, nothing. I'm reading it out with inputstream.read(). The handshake is in plain text and works wonderful.

I've looked at websocket data format, but i don't get how i should use it.

Slightly duplicate with Websocket Java Server. Not sending message nor receiving --> but I don't get it, anyway.

Thanks for any suggestions!

Community
  • 1
  • 1
SEUH
  • 314
  • 3
  • 15

1 Answers1

1

The data that the client sends is masked. You must get the data from the frame and unmask it.

The unmask function should be something like this:

var DECODED = "";
for (var i = 0; i < ENCODED.length; i++) {
    DECODED[i] = ENCODED[i] ^ MASK[i % 4];
}

Read: https://developer.mozilla.org/en-US/docs/WebSockets/Writing_WebSocket_servers#Step_2.3A_Exchanging_Data_Frames

This is a tutorial of how to develop a WebSocket server in C#, probably very similar to Java.

vtortola
  • 34,709
  • 29
  • 161
  • 263