0
votes

I'm trying the Netty's WebSocketServer(Netty WebSocketServer). I want to send messages to this server from a native web socket client(from: http://www.tutorialspoint.com/html5/html5_websocket.htm) with a code as follows:

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function WebSocketTest()
{
  if ("WebSocket" in window)
  {
     alert("WebSocket is supported by your Browser!");
     // Let us open a web socket
     var ws = new WebSocket("ws://localhost:3210/websocket");
     ws.onopen = function()
     {
        // Web Socket is connected, send data using send()
        ws.send("Message to send");
        alert("Message is sent...");
     };
     ws.onmessage = function (evt) 
     { 
        var received_msg = evt.data;
        alert("Message is received...");
     };
     ws.onclose = function()
     { 
        // websocket is closed.
        alert("Connection is closed..."); 
     };
  }
  else
  {
     // The browser doesn't support WebSocket
     alert("WebSocket NOT supported by your Browser!");
  }
}
</script>
</head>
<body>
<div id="sse">
   <a href="javascript:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html>

However in the handler's messageReceived method, it sees the incoming message in BigEndianHeapChannelBuffer type.

What do I need to change in server code?

2

2 Answers

0
votes

Please note that netty's stable release doesn't support the newer websocket versions used by browsers. You might want to check if websocket connection is being established successfully.

0
votes

Which browser are you using?

The code in Netty 3.2 supports HyBi-00. Most browsers have moved on from that version. See post.

Netty 3.3 (3.2 branch of the source) and 4.0 (master branch of the source) contains support for the latest web socket standards (RFC 6455).

My recommendation is to use netty 3.2 branch.

Hope this helps.