0

I have a problem with Apache mina and websocket communication.

The handshake works fine and I have a working connection with my server, but if my client sends a string to my server, the strings receive but I can't show them in console.

public void messageReceived(IoSession session, Object message) throws Exception {
System.out.println(message.toString());
if(message.toString().length() > 20 && message.toString().substring(0, 17).equals("Sec-WebSocket-Key")) {
  new Thread(new WebsocketHandler(session, message)).start();
} else {
  //
}}

My server log says that the message receives

INFO: RECEIVED: HeapBuffer[pos=0 lim=10 cap=2048: 81 84 88 45 2B 31 DC 00 78 65]

But I can't show the message, I think it's my TextLineCodecFactory filter but I don't know why.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Norwido
  • 51
  • 1
  • 7

2 Answers2

1

Try this codec which handles everything websocket related: https://issues.apache.org/jira/browse/DIRMINA-907

AndresQ
  • 803
  • 5
  • 19
0

add "\r\n" when write.

byte[] bytes = content.getBytes("UTF-8");
outputStream.write(bytes);
outputStream.write("\r\n".getBytes());