NaikSoftware / StompProtocolAndroid

STOMP protocol via WebSocket for Android
MIT License
597 stars 265 forks source link

Sending a long message #95

Open majidasgari opened 6 years ago

majidasgari commented 6 years ago

Hi there. I am using this brilliant library for a stomp connection on android. Everything works for sending and subscribing message expect when I tries to send long messages to server. The length of message is 255612 characters. Connection closed on sending message without any errors. No exception in lifecycleEvent arises, and the log shows library not sending full message to server:

D/WebSocketsConnectionProvider: Send STOMP message: SEND
                                destination:/ws/commandResult

                                {"command":"screenshot","payload":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAQ4B4ADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDyeiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAPur/AIU18NP+ha/8rPiH/wCW1H/Cmvhp/wBC1/5WfEP/AMtq9Oor+7v9T+EP+iV4d/8ADHlf/wAyH/Jd/wATIfSN/wCj/wDjP/4tXj3/AOiE8x/4U18NP+ha/wDKz4h/+W1H/Cmvhp/0LX/lZ8Q//LavTqKP9T+EP+iV4d/8MeV//Mgf8TIfSN/6P/4z/wDi1ePf/ohPMf8AhTXw0/6Fr/ys+If/AJbUf8Ka+Gn/AELX/lZ8Q/8Ay2r06ij/AFP4Q/6JXh3/AMMeV/8AzIH/ABMh9I3/AKP/AOM//i1ePf8A6ITzH/hTXw0/6Fr/AMrPiH/5bUf8Ka+Gn/Qtf+VnxD/8tq9Ooo/1P4Q/6JXh3/wx5X/8yB/xMh9I3/o//jP/AOLV49/+iE8x/wCFNfDT/oWv/Kz4h/8AltR/wpr4af8AQtf+VnxD/wDLavTqKP8AU/hD/oleHf8Awx5X/wDMgf8AEyH0jf8Ao/8A4z/+LV49/wDohPMf+FNfDT/oWv8Ays+If/ltR/wpr4af9C1/5WfEP/y2r06ij/U/hD/oleHf/DHlf/
D/WebSocketsConnectionProvider: Emit lifecycle event: CLOSED

I developed a node-js client and sent this long messages by that library successfully.

majidasgari commented 6 years ago

I found that the origin of problem is "The decoded text message was too big for the output buffer and the endpoint does not support partial messages" in writerRunnable of RealWebSocket class.

I have set the maximum size of message by registration?.setMessageSizeLimit(5000000) on the server side. I must set the size on okhttp3 library.

similar issue on another libraries

majidasgari commented 6 years ago

I used java_websocket instead okhttp3 and got same error, this time more clear error received, at least we have error in the console

D/WebSocketsConnectionProvider: onClose: code=1009 reason=The decoded text message was too big for the output buffer and the endpoint does not support partial messages remote=true
D/WebSocketsConnectionProvider: Emit lifecycle event: CLOSED

I'm sure the server has configured correctly but I don't know how can i configure the client :(

forresthopkinsa commented 6 years ago

Similar to #39; however, that issue is about receiving large payloads, and this issue seems to be about sending large payloads. Am I understanding that correctly?

majidasgari commented 6 years ago

Yes. Exactly. Do you have any plans to support/resolve this issue?

NaikSoftware commented 6 years ago

Stomp designed for small text messages. But thanks for issue, I am will investigate this problem, and if okhttp-ws support changing buffer size I am try to fix.

Otunbatj commented 6 years ago

I am using this library for socket connection i'm able to receive message successfully through stompClient.topic().subscribe() but stompClient.send().subscribe() is not sending messages to the server...

This is my first time of using this library as I just learned of it. My code for connecting to the web socket is as below:

`public void connectSocket(){ TAG="LongOperation"; mStompClient = Stomp.over(WebSocket.class, TerminalDetails.WEB_SOCKET_URL); mStompClient.connect();

mStompClient.topic("/pos/asycnronous").subscribe(topicMessage -> {
    Log.d(TAG, topicMessage.getPayload());
    mResult = topicMessage.getPayload();
    try {
        JSONObject jsonObject = new JSONObject(mResult);
        if (jsonObject.getString("messageType").equalsIgnoreCase(TerminalDetails.RESP_ACTIVATE_POS)
                && jsonObject.getString("tellerId").equalsIgnoreCase(TerminalDetails.tellerID)) {
            listener.onMessageReceived(jsonObject);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
});

mStompClient.send("/api/poschannel", "My first STOMP message!").subscribe(aVoid -> {
    Log.d(TAG, "STOMP echo send successfully");
}, throwable -> {
    Log.e(TAG, "Error send STOMP echo", throwable);
});

mStompClient.lifecycle().subscribe(lifecycleEvent -> {
    switch (lifecycleEvent.getType()) {

        case OPENED:
            Log.d(TAG, "Stomp connection opened");
            break;

        case ERROR:
            Log.e(TAG, "Error", lifecycleEvent.getException());
            break;

        case CLOSED:
            Log.d(TAG, "Stomp connection closed");
            break;
    }
});

}`

I appreciate your prompt response, thanks in anticipation.

victorgonzcuriel commented 6 years ago

Any workaround for this? I'm working with a spring web app with websocket and a mobile app for remote control. I've already configured the server, but can't configure the client side. Getting this error on console after trying to send a large message:

D/class com.stomped.stomped.connection.WebSocketConnector: WebSocket is closing: The decoded text message was too big for the output buffer and the endpoint does not support partial messages

afosid commented 4 years ago

I have sent a pull request about the problem. Messages which are larger than 8k are now splitted into chunks. Stomp servers merge them as a single message. #163