TakahikoKawasaki / nv-websocket-client

High-quality WebSocket client implementation in Java.
Apache License 2.0
2.03k stars 292 forks source link

Websocket makes two connections #245

Closed vsranjitroshan closed 1 year ago

vsranjitroshan commented 1 year ago

I am creating a websocket connection to a server hosted by QWebSocketServer over my localhost. Whenever I try to connect, the onConnected function is called twice. Is this only supposed to be called once right? this causes some problems with the server side code, since there are now two clients there.

@Override public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception { websocket.sendText("Hello"); Log.i("WS", "CONNECTED"); }

I am only calling this code once in my android app.

factory = new WebSocketFactory().setConnectionTimeout(500); nvWebSocketListener = new NvWebSocketListener(); try { webSocket = factory.createSocket("ws://192.168.0.25:12345"); webSocket.addListener(nvWebSocketListener); webSocket.connect(); } catch (IOException e) { throw new RuntimeException(e); } catch (WebSocketException e) { throw new RuntimeException(e); }

Can you please guide on what can be done to avoid this issue?

vsranjitroshan commented 1 year ago

There was a error on the server side, it drops the connection due to some reason and again the connection is established. This library is working amazingly. Thanks @TakahikoKawasaki