My goal is to implement the RFC6455. I use Java for the back end and JavaScript WebSocket API for the front end.
What I have done:
- Knowning that
there is no JavaScript APIto send Ping/Pong frame from this SO question. So, I decided to create one from the front end. - Tried to sent a
Pingframe from the server.
// 137 = 1 0 0 0 1 0 1 0 // opcode = 0x09
// 0 = 0 0 0 0 0 0 0 0 // Payload len = 0
socket.getOutputStream.write(new byte[(byte) 137, 0]);
My expected result: The browser's DevTools > Network > localhost > Messages should have Ping frame that was sent by the server.
My actual result: The browser's DevTools does not receive the Ping frame nor the WebSocket.onmessage. So, I am not sure how to handle the Ping from and then send the Pong frame with WebSocket.send