I'm using the following Arduino function to send data across websocket communication:
void WebSocketClient::sendEncodedData(String& str, uint8_t opcode) {
uint8_t mask[4];
int size = str.length()+1;
// Opcode; final fragment
socket_client->write(opcode | WS_FIN);
// NOTE: no support for > 16-bit sized messages
if (size > 125) {
socket_client->write(WS_SIZE16 | WS_MASK);
socket_client->write((uint8_t)(size >> 8));
socket_client->write((uint8_t)(size & 0xFF));
}
else {
socket_client->write((uint8_t)size | WS_MASK);
}
mask[0] = random(0, 256);
mask[1] = random(0, 256);
mask[2] = random(0, 256);
mask[3] = random(0, 256);
socket_client->write(mask[0]);
socket_client->write(mask[1]);
socket_client->write(mask[2]);
socket_client->write(mask[3]);
for (int i = 0; i<size; ++i) {
socket_client->write(str[i] ^ mask[i % 4]);
}
}
This function belongs to this Arduino websocket client implementation library.
My java websocket server code using Tyrus project is as the following:
public static void runServer() {
Server server = new Server("192.168.1.105", 8025, "/websockets", ArduinoEndPoint.class);
try {
server.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please press a key to stop the server.");
reader.readLine();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
server.stop();
}
}
ArduinoEndPoint class in the above code represents a simple implementation of the @onMessage, @onOpen and @onClose annotated methods.
My problem is that when I'm sending a messages less than 25 characters from Arduino, it will be received on the server, but all messages more than 25 characters is not received.
Websocket server is working with any message size using Tyrus java websocket client implementation. What I'm missing here?
-
Which version of Tyrus are you using? (1.10 is latest stable). This seems like an issue with grizzly server, since Tyrus would trigger @On* method, when it receives any message.. Anyway, we have lots of tests which are sending similar message sizes and it all passes, so could it be some TCP related setting? Like buffering on either side of the connection..Pavel Bucek– Pavel Bucek2015年04月13日 08:22:30 +00:00Commented Apr 13, 2015 at 8:22
1 Answer 1
According to the Arduino-Websocket documentation it supports 65535 characters in length (16 bit) so it is not the issue in Arduino-Websocket client code but something to do with Tyrus server.
Try to create a Web Application in Tomcat 8 which supports Web Socket and connect to using Arduino and see. I have done this and didn't face any issues.