Android Question Sending binary data over WebSocket?

daemon

Active Member
Licensed User
The WebSocket client library has only one method, SendText, to send data to server.
Is there any plan to support sending binary data (Byte array) such as binary file contents?
Is that even there in specification?

For now, I guess I should use ByteConverter and some sort of custom protocol?
 

Erel

Administrator
Staff member
Licensed User
The WebSocket client doesn't support binary transfers. If the file is small then you can encode it as base64 string. However for larger files it is recommended to use a standard http request. Otherwise you will block the single WebSocket connection.

There is such an example in B4J that combines WebSocket with a standard handler:
http://basic4ppc.com:51042/ (file upload with websockets).
 

daemon

Active Member
Licensed User
I tried with base64 encoding.
It worked for small files of ~8KB. But for ~50KB file, my connection disconnects.
I'm doing everything in may Main module but it continues to function. I do not get ANR.

What could be wrong?
I'm now trying to move some parts to a service.
 

daemon

Active Member
Licensed User
OK, here is the reason specified in _Close event:
Frame size of 65975 bytes exceeds maximum accepted frame size
WebSockets connection lost
WebSockets internal error (java.nio.channels.ClosedChannelException)

How can I go beyond max limit?
 

daemon

Active Member
Licensed User
OK, here is the reason specified in _Close event:
Frame size of 65975 bytes exceeds maximum accepted frame size
WebSockets connection lost
WebSockets internal error (java.nio.channels.ClosedChannelException)

How can I go beyond max limit?
Never mind.

Found that it was server configuration. It is working after changing server config maxReceivedFrameSize.
https://github.com/Worlize/WebSocket-Node/wiki/Documentation

However, it would be good if fragmentation was supported.
 

daemon

Active Member
Licensed User
I hit the wall again.
For file size ~98KB with base64 encoding, I get following error:

WebSockets internal error (de.tavendo.autobahn.WebSocketException: message payload exceeds payload limit)

I see that the library has maximum payload size set to 131072 bytes (128 KB).
May I request option to set it to a higher value?
 
Top