[英]Arduino websocket client and Tyrus websocket server message communication issue?
I'm using the following Arduino function to send data across websocket communication: 我正在使用以下Arduino函数通过WebSocket通信发送数据:
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 . 该函数属于此Arduino websocket客户端实现库 。
My java websocket server code using Tyrus project is as the following: 我的使用Tyrus项目的java websocket服务器代码如下:
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. 上面代码中的ArduinoEndPoint类代表@ onMessage,@ onOpen和@onClose注释方法的简单实现。
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. 我的问题是,当我从Arduino发送少于25个字符的消息时,它将在服务器上接收到,但是超过25个字符的所有消息都没有收到。
Websocket server is working with any message size using Tyrus java websocket client implementation. Websocket服务器正在使用Tyrus Java Websocket客户端实现处理任何消息大小。 What I'm missing here? 我在这里想念的是什么?
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. 根据Arduino-Websocket文档,它支持65535个字符的长度(16位),因此这不是Arduino-Websocket客户端代码中的问题,而是与Tyrus服务器有关。
Try to create a Web Application in Tomcat 8 which supports Web Socket and connect to using Arduino and see. 尝试在Tomcat 8中创建一个支持Web Socket的Web应用程序,并使用Arduino连接并查看。 I have done this and didn't face any issues. 我已经做到了,没有遇到任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.