[Python] How set maximum length of message for Autobahn Websocket?

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I use "Autobahn" on android (Java) as client and on linux as server (python). When I send big messages from client we have disconnetion. That's because of exceeding of max message length. For different devices this limit is different too. For "Minix Neo X8" is 2Mb and for "HTC One" is 8Mb. What is the problem? How can I set max length message by force?

    import de.tavendo.autobahn.WebSocketConnection;
    import de.tavendo.autobahn.WebSocketException;
    import de.tavendo.autobahn.WebSocketHandler;
    import de.tavendo.autobahn.WebSocketOptions;


    WebSocketManager mWebSocketManager = new WebSocketManager();
    MessageHandler messageHandler = new MessageHandler();

    private final WebSocketConnection mConnection = new WebSocketConnection();

    private void createSocket() {
    try {
    mConnection.connect("ws://192.168.45.86:1488/echo", mWebSocketManager);
    } catch (WebSocketException e) {

    Log.d(TAG, e.toString());
    }
    }

    private class WebSocketManager extends WebSocketHandler {
    @Override
    public void onTextMessage(String data) {
    try {
    messageHandler.parseMessage(data);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    }

    @Override
    public void onOpen() {
    Log.d("RECD", "Connection established");
    messageHandler.sendMessage("Request", "Login", 16, null);
    }

    @Override
    public void onClose(int code, String reason) {
    }
    }


    I try use setMaxMessagePayloadSize for setting maximum length of message (in in octets):

    private void createSocket() {
    try {
    WebSocketOptions options = new WebSocketOptions();
    options.setMaxMessagePayloadSize(33554432);
    mConnection.connect("ws://192.168.45.86:1488/echo", mWebSocketManager , options);

    } catch (WebSocketException e) {

    Log.d("Error", e.toString());
    }
    }


    but it does not affect the length of the message. If not use setMaxMessagePayloadSize, then I get an exception, when the message exceeds 65536 bytes:


    W/System.err﹕ de.tavendo.autobahn.WebSocketException: message payload exceeds payload limit
    ​

    The documentation states that the default length of message is 4 mb.

    Continue reading...

Compartilhe esta Página