koush / AndroidAsync

Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
Other
7.51k stars 1.56k forks source link

Following the basic websocket example code, but #715

Closed chenzx closed 1 year ago

chenzx commented 1 year ago
E/WebRTC-Test/Signaling: Error onCompleted: Unable to complete websocket handshake
    com.koushikdutta.async.http.WebSocketHandshakeException: Unable to complete websocket handshake
        at com.koushikdutta.async.http.AsyncHttpClient.lambda$websocket$2(AsyncHttpClient.java:686)
        at com.koushikdutta.async.http.AsyncHttpClient$$ExternalSyntheticLambda0.onConnectCompleted(Unknown Source:6)
        at com.koushikdutta.async.http.AsyncHttpClient.reportConnectedCompleted(AsyncHttpClient.java:167)
        at com.koushikdutta.async.http.AsyncHttpClient.access$200(AsyncHttpClient.java:49)
        at com.koushikdutta.async.http.AsyncHttpClient$4.setDataEmitter(AsyncHttpClient.java:399)
        at com.koushikdutta.async.http.AsyncHttpResponseImpl.emitter(AsyncHttpResponseImpl.java:76)
        at com.koushikdutta.async.http.HttpTransportMiddleware$2.onStringAvailable(HttpTransportMiddleware.java:123)
        at com.koushikdutta.async.LineEmitter.onDataAvailable(LineEmitter.java:42)
        at com.koushikdutta.async.Util.emitAllData(Util.java:23)
        at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:160)
        at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:878)
        at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:726)
        at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:46)
        at com.koushikdutta.async.AsyncServer$8.run(AsyncServer.java:680)

Having had a look at code:

    public Future<WebSocket> websocket(String uri, String protocol, final WebSocketConnectCallback callback) {
        final AsyncHttpGet get = new AsyncHttpGet(uri.replace("ws://", "http://").replace("wss://", "https://"));
        return websocket(get, protocol, callback);
    }

The sample code in README use (String)null for protocol, is it ok?

chenzx commented 1 year ago

Hi, i after checked the code, i found i didn't config the server side .websocket() method's regex arg and it occasionally doesn't match with client setting, after changed to "/*" it worked now.

        httpServer.websocket("/*", this);
        httpServer.listen(AsyncServer.getDefault(), tcpListenPort);