TakahikoKawasaki / nv-websocket-client

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

Failed to send an opening handshake request to the server: Connection reset #188

Open trunggn opened 5 years ago

trunggn commented 5 years ago

I use below code to connect to secure websocket server (wss)

WebSocketFactory factory = new WebSocketFactory();
factory.setVerifyHostname(false);

//WebSocket ws = factory.createSocket("wss://demos.kaazing.com/echo"); 
WebSocket ws = factory.createSocket("wss://bot.fpt.ai/ws/livechat");
ws.connect();

It work fine when connect to "wss://demos.kaazing.com/echo" but error when connect to "wss://bot.fpt.ai/ws/livechat"

com.neovisionaries.ws.client.WebSocketException: Failed to send an opening handshake request to the server: Connection reset
    at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:3402)
    at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:3288)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2326)
    at test3.HelloWSS.main(HelloWSS.java:51)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:207)
    at java.net.SocketInputStream.read(SocketInputStream.java:133)
    at com.ibm.jsse2.a.a(a.java:110)
    at com.ibm.jsse2.a.a(a.java:141)
    at com.ibm.jsse2.qc.a(qc.java:691)
    at com.ibm.jsse2.qc.h(qc.java:266)
    at com.ibm.jsse2.qc.a(qc.java:214)
    at com.ibm.jsse2.h.write(h.java:10)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:93)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:151)
    at java.io.FilterOutputStream.flush(FilterOutputStream.java:151)
    at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:3395)
    ... 3 more
devilk10 commented 3 years ago

Can you check if your signalling server is based on socket.io, cause Socket.io and Websocket client can not communicate. This is what Socket.io official doc says

Although Socket.IO indeed uses WebSocket as a transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.