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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

A prior answer has the parse + demasking example in java - stackoverflow.com/a/18371023/775715

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.