AWT
AWT

Reputation: 381

Arduino websocket client and Tyrus websocket server message communication issue?

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?

Upvotes: 0

Views: 555

Answers (1)

shazin
shazin

Reputation: 21893

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.

Upvotes: 0

Related Questions