1

I am using android autobahn websocket for establish connection between android and python tornado socket server .

Below is the autobahn websocket code which am using in android .

public void start() {

    final String wsuri = ip;

    try {
        mConnection.connect(wsuri, new WebSocketHandler() {

            @Override
            public void onOpen() {
                Log.d(TAG, "Connected to " + wsuri);

            }

            @Override
            public void onTextMessage(String payload) {
                Log.d(TAG, "Got echo: " + payload);

            try{

                InputStream stream = new ByteArrayInputStream(Base64.decode((payload).getBytes(), Base64.DEFAULT));
                Bitmap bitmap = BitmapFactory.decodeStream(stream);

                image.setImageBitmap(bitmap);

            } catch (Exception e) {
                Log.d("got exception:", e.toString());

            }



            }

            @Override
            public void onClose(int code, String reason) {
                Log.d(TAG, "Connection lost.");
                Toast.makeText(Project12.this, "Server is Closed", Toast.LENGTH_SHORT).show();
            }
        });

    } catch (WebSocketException e) {

        Log.d(TAG, e.toString());
        Toast.makeText(Project12.this, "Given IP Adress is not available", Toast.LENGTH_SHORT).show();
        return;
    }
}

All messages are receiving in public void onTextMessage(Object payload) method.

Problem is that when am sending images less than 128 kb from python socket server, am able to receive it .But when am sending images having size more than 128 kb it shows error which mention below.

WebSocketException (de.tavendo.autobahn.WebSocketException: frame payload too large)

So how can i increase frame payload size.

1 Answers1

0

you need to use WebSocketOptions like this:

  WebSocketOptions options = new WebSocketOptions();
  options.setMaxMessagePayloadSize(1000000); //max size of message
  options.setMaxFramePayloadSize(1000000); //max size of frame
  mConnection.connect(wsuri, new WebSocketHandler() {},options);
issam
  • 697
  • 1
  • 9
  • 15