Java websocket client onMessage not called

25 views Asked by At

I wrote a websocket api client in java using javax.websocket, ut the onMessage method is not called every time. I captured the websocket traffic with wireshark and there I recieve all messages as intented. But for example when recieving this message the onMessage method is not called:

Frame 81227: 1151 bytes on wire (9208 bits), 1151 bytes captured (9208 bits) on interface \Device\NPF_{CE827496-7DF6-4B49-B85E-D5DBC67BB866}, id 3
Ethernet II, Src: PCSSystemtec_07:**:** (08:00:27:07:**:**), Dst: 0a:00:27:00:**:** (0a:00:27:00:**:**)
Internet Protocol Version 4, Src: 192.*.*.*, Dst: 192.*.*.*
Transmission Control Protocol, Src Port: 8123, Dst Port: 56643, Seq: 42747, Ack: 537, Len: 1097
[27 Reassembled TCP Segments (37601 bytes): #81115(4), #81116(1460), #81118(1460), #81119(1460), #81121(1460), #81122(1460), #81124(1460), #81125(1460), #81127(1460), #81128(1460), #81130(1460), #81131(1460), #81133(1460), #81134(1460), ]
WebSocket
    1... .... = Fin: True
    .000 .... = Reserved: 0x0
    .... 0001 = Opcode: Text (1)
    0... .... = Mask: False
    .111 1110 = Payload length: 126 Extended Payload Length (16 bits)
    Extended Payload length (16 bits): 37597
    Payload
        Text [truncated]: {"id":2,"type": "result","success":true,"result": [{"area_id":null,"config_entry_id":"1512d731251002d8fb615e1c97e29847","device_id":"fce9ab5388aeb99df26e99fe95befa52","disabled_by":null,"entity_category":"config","entity_
Line-based text data (1 lines)
     [truncated]{"id":2,"type": "result","success":true,"result": [{"area_id":null,"config_entry_id":"1512d731251002d8fb615e1c97e29847","device_id":"fce9ab5388aeb99df26e99fe95befa52","disabled_by":null,"entity_category":"config","entity_id":"u

For this message it works:

Frame 81113: 161 bytes on wire (1288 bits), 161 bytes captured (1288 bits) on interface \Device\NPF_{CE827496-7DF6-4B49-B85E-D5DBC67BB866}, id 3
Ethernet II, Src: PCSSystemtec_07:**:** (08:00:27:07:**:**), Dst: 0a:00:27:00:**:** (0a:00:27:00:**:**)
Internet Protocol Version 4, Src: 192.*.*.*, Dst: 192.*.*.*
Transmission Control Protocol, Src Port: 8123, Dst Port: 56643, Seq: 6136, Ack: 486, Len: 107
[5 Reassembled TCP Segments (5947 bytes): #81107(1460), #81108(1460), #81110(1460), #81111(1460), #81113(107)]
WebSocket
    1... .... = Fin: True
    .000 .... = Reserved: 0x0
    .... 0001 = Opcode: Text (1)
    0... .... = Mask: False
    .111 1110 = Payload length: 126 Extended Payload Length (16 bits)
    Extended Payload length (16 bits): 5943
    Payload
        Text [truncated]: {"id":1,"type": "result","success":true,"result": [{"area_id":null,"configuration_url":null,"config_entries":["1512d731251002d8fb615e1c97e29847"],"connections":[],"disabled_by":null,"entry_type":"service","hw_version":nul
Line-based text data (1 lines)
     [truncated]{"id":1,"type": "result","success":true,"result": [{"area_id":null,"configuration_url":null,"config_entries":["1512d731251002d8fb615e1c97e29847"],"connections":[],"disabled_by":null,"entry_type":"service","hw_version":null,"id"

Java Code

@ClientEndpoint
public class WebsocketApiClient {
    private final Logger logger = Logger.getLogger(this.getClass().getName());

    public WebsocketApiClient(URI endpointURI) {
        try {
            WebSocketContainer container = ContainerProvider
                    .getWebSocketContainer();
            container.connectToServer(this, endpointURI);
            logger.log(Level.INFO, "connected to websocket");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @OnMessage
    public void onMessage(String message) {
        logger.log(Level.INFO, "received message: " + message);
    }

I read some posts that there is a length limit at 20mb. Maybe that has to do with the problem, although mine has only 1kb.

Help is very appreciated. Thanks in advance

0

There are 0 answers