Jeevanantham
Jeevanantham

Reputation: 1032

JSR 356 WebSocket Max message size configuration failed

I am using the Websocket for data transaction, client side is listened through Tyrus client end point api. While transfer the message size of 5kb or less from server it reaches the client with out failure but any message size above 5kb is not reaching the client and communication on that particular session is gone. So i try to set the message buffer size as below on session but it always remains zero, tried printing below the configuration immediately after setting too but that also returns zero.

Even tried configure message size in client endpoint message listener

@OnMessage(maxMessageSize =1024*64)

So how to increase the message buffer size in websocket?

session.setMaxTextMessageBufferSize(64 * 1024);
session.setMaxBinaryMessageBufferSize(64 * 1024);
System.out.println("Session Binary size >> " + session.getMaxBinaryMessageBufferSize());
System.out.println("Session Text size >> " + session.getMaxTextMessageBufferSize());

Upvotes: 2

Views: 3790

Answers (2)

Javi
Javi

Reputation: 679

I had same problem (all messages received in my Android app were limited to 64KB from server side) and the solution that I found was to increase the binary limit size:

1) client: adding next line in the class definition of your WebSocket implementation

@WebSocket(maxTextMessageSize = 640 * 1024,
           maxBinaryMessageSize = 640 * 1024)  

2) server: although not in my control (it is a 3rd Party provider), it seems that they managed to configure it with next commands:

WebSocketSession ---> setBinaryMessageSizeLimit
WebSocketPolicy.newServerPolicy().setMaxBinaryMessageSize(100000);

I have read that a better solution would have been to get 64KB chunks of the messages directly managed by the client, but in my case I was not able to get it working in the OnWebSocketMessage implementation of my app client, even with the binary definition normally used by Jetty protocol:

@OnWebSocketMessage
public void onMessage(Session session, 
                      byte[] message, int offset, int length)

Anyhow I hope that some WebSocket expert may give us some better solution that my proposed one. Cheers!

Upvotes: 1

kuhajeyan
kuhajeyan

Reputation: 11057

You should set this on both side of your peers, i.e on your server(peer) side where you receive the message as well your peer which receive message from server.

@OnMessage(maxMessageSize = 1024 * 1024) public void onBinaryMessage(Session session, ByteBuffer msg) { //todo }

Upvotes: 3

Related Questions