crossbario / autobahn-java

WebSocket & WAMP in Java for Android and Java 8
https://crossbar.io/autobahn
MIT License
1.52k stars 427 forks source link

My socket is connected and want to receive message continuously? #510

Closed sovoereign closed 3 years ago

sovoereign commented 3 years ago

I can receive a message when I connect to the socket. Once I connected to the socket, my server responds whenever something happens so how will I receive a message continuously.

om26er commented 3 years ago

If you look at this example https://github.com/crossbario/autobahn-java#websocket-on-android

Everytime your server sends a message, the onMessage callback will be called. So in your code, please make sure you have the onMessage callback.

sovoereign commented 3 years ago

@om26er Yes I have onMessage callback, but receiving a response when I connect to the server

   if(!connection.isConnected()){
                                connection.connect(getWssUrl(s_driver_api_key),otherStrings, new WebSocketConnectionHandler() {
                                    @Override
                                    public void onConnect(ConnectionResponse response) {
                                        System.out.println("Connected to server-----"+response);
                                    }

                                    @Override
                                    public void onOpen() {
                                        System.out.println("Connection onOpen------");
                                    }

                                    @Override
                                    public void onClose(int code, String reason) {
                                        System.out.println("Connection closed------"+code);
                                        System.out.println("Connection closed------"+reason);
                                    }

                                    @Override
                                    public void onMessage(String payload) {
                                        System.out.println("Received message:----- " + payload);
                                    }
                                });
                            }else{

                                System.out.println("Connected:----- " );

                            }
sovoereign commented 3 years ago

[8,"driverXYZapikey",{"event":51,"booking":"7A1708ED","message":"Booking #7A1708ED on 29 September - 16:39 was updated. Please check new details."}] Receiving this message on the browser, not receiving in socket

om26er commented 3 years ago

Is the websocket server public, maybe I can try to reproduce the issue (and debug, if needed). Is it possible for you to share the websocket URI ?

sovoereign commented 3 years ago

I want to receive message continuously, i can send message but not receiving after establishing connection but working fine with browser.

Screenshot 2020-09-30 at 11 32 55 AM

sometime showing in onPing method onPing isBinary:----- [B@dc3be9c Screenshot 2020-09-30 at 11 34 49 AM

om26er commented 3 years ago

There is something very odd happening here. The server that you are trying to connect talks WAMPv1, this library now only supports WAMPv2. So I'd say this is a lost cause.

om26er commented 3 years ago

To elaborate on that. Autobahn Java only support WAMP protocol version 2. However, the server that you are trying to connect is only talks WAMP protocol version 1. Here is the screenshot of the errors. You can clearly see your server response returns this specific line in its response headers.

Sec-WebSocket-Protocol: wamp

wamp1

sovoereign commented 3 years ago

@om26er okay got your point, but why does socket connect?

oberstet commented 3 years ago

the websocket opening handshake fails, since the websocket subprotocol negotiation runs into a mismatch. use a wamp2 server or use plain websocket