B4J Question jWebSocketClient - cant connect

Alexander Stolte

Expert
Licensed User
Longtime User
I get the following error message if i try to connect to "wss://b4x.com:51041/smiley/ws"
B4X:
Waiting for debugger to connect...
Program started.
2023-10-11 09:54:11.167:INFO::JavaFX Application Thread: Logging initialized @3000ms to org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.websocket.api.UpgradeException: 0 null
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.onComplete(WebSocketUpgradeRequest.java:515)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:193)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:185)
    at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:464)
    at org.eclipse.jetty.client.HttpReceiver.abort(HttpReceiver.java:545)
    at org.eclipse.jetty.client.HttpReceiver.responseFailure(HttpReceiver.java:436)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.failAndClose(HttpReceiverOverHTTP.java:369)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.earlyEOF(HttpReceiverOverHTTP.java:338)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1476)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.shutdown(HttpReceiverOverHTTP.java:209)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:147)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:73)
    at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:133)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:155)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ssl.SslConnection$2.run(SslConnection.java:136)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.EOFException: HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<-DecryptedEndPoint@5d3de879{b4x.com/67.227.218.133:51041<->/192.168.188.20:54622,OPEN,fill=-,flush=-,to=4/0}->HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]->SocketChannelEndPoint@4d9b97eb{b4x.com/67.227.218.133:51041<->/192.168.188.20:54622,ISHUT,fill=-,flush=-,to=4/0}{io=0/0,kio=0,kro=1}->SslConnection@61f26ca7{NEED_WRAP,eio=-1/-1,di=-1}=>HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]
    ... 13 more
org.eclipse.jetty.websocket.api.UpgradeException: 0 null
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.onComplete(WebSocketUpgradeRequest.java:522)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:193)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:185)
    at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:464)
    at org.eclipse.jetty.client.HttpReceiver.abort(HttpReceiver.java:545)
    at org.eclipse.jetty.client.HttpReceiver.responseFailure(HttpReceiver.java:436)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.failAndClose(HttpReceiverOverHTTP.java:369)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.earlyEOF(HttpReceiverOverHTTP.java:338)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1476)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.shutdown(HttpReceiverOverHTTP.java:209)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:147)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:73)
    at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:133)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:155)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ssl.SslConnection$2.run(SslConnection.java:136)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
    at java.base/java.lang.Thread.run(Thread.java:834)
java.util.concurrent.ExecutionException: org.eclipse.jetty.websocket.api.UpgradeException: 0 null
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
    at anywhersoftware.b4j.objects.WebSocketClientWrapper.Close(WebSocketClientWrapper.java:102)
    at anywhersoftware.b4j.objects.WebSocketClientWrapper$WSHandler.onWebSocketError(WebSocketClientWrapper.java:163)
    at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onError(JettyListenerEventDriver.java:112)
    at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingError(AbstractEventDriver.java:96)
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.handleException(WebSocketUpgradeRequest.java:528)
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.onComplete(WebSocketUpgradeRequest.java:522)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:193)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:185)
    at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:464)
    at org.eclipse.jetty.client.HttpReceiver.abort(HttpReceiver.java:545)
    at org.eclipse.jetty.client.HttpReceiver.responseFailure(HttpReceiver.java:436)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.failAndClose(HttpReceiverOverHTTP.java:369)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.earlyEOF(HttpReceiverOverHTTP.java:338)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1476)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.shutdown(HttpReceiverOverHTTP.java:209)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:147)
    at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:73)
    at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:133)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:155)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ssl.SslConnection$2.run(SslConnection.java:136)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.eclipse.jetty.websocket.api.UpgradeException: 0 null
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.onComplete(WebSocketUpgradeRequest.java:515)
    ... 19 more
Caused by: java.io.EOFException: HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<-DecryptedEndPoint@5d3de879{b4x.com/67.227.218.133:51041<->/192.168.188.20:54622,OPEN,fill=-,flush=-,to=4/0}->HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]->SocketChannelEndPoint@4d9b97eb{b4x.com/67.227.218.133:51041<->/192.168.188.20:54622,ISHUT,fill=-,flush=-,to=4/0}{io=0/0,kio=0,kro=1}->SslConnection@61f26ca7{NEED_WRAP,eio=-1/-1,di=-1}=>HttpConnectionOverHTTP@7a0e862d(l:/192.168.188.20:54622 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@edccf14(exchange=HttpExchange@21053c9d req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@75f3a03b(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@5bc0994c{s=START}],recv=HttpReceiverOverHTTP@330c594f(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]
    ... 13 more
I have already found several threads with this problem, but without working solutions.

I'm using this code:
B4X:
    Dim  ws As WebSocketClient
    ws.Initialize("ws")
    Dim ssl As JavaObject
    ssl.InitializeNewInstance("org.eclipse.jetty.util.ssl.SslContextFactory", Array(True))
    Dim jo As JavaObject = ws
    Dim wsc As JavaObject
    wsc.InitializeNewInstance("org.eclipse.jetty.websocket.client.WebSocketClient", Array(ssl))
    jo.SetField("wsc", wsc)
    Sleep(1000)
    ws.Connect("wss://b4x.com:51041/smiley/ws")
    Wait For ws_Connected
    Log("connected")
B4J Version: 10 Beta #2
jWebSocketClient Version: 1.13
Java Version: 11
 

Attachments

  • wssconnection.zip
    2.2 KB · Views: 177

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see it too and it is probably related to B4X server configuration.

You can make a test by starting two instances of B4J.
1. Create a new server project and run it in release mode.
2. Create a new non-ui project:
B4X:
Sub Process_Globals
    Private client As WebSocketClient
End Sub

Sub AppStart (Args() As String)
    Start
    StartMessageLoop
End Sub

Private Sub Start
    client.Initialize("client")
    client.Connect("ws://127.0.0.1:51042/guessmynumber_ws/ws")
    Wait For client_Connected
    Log("connected")
End Sub

Private Sub client_Closed (Reason As String)
    Log("closed: " & Reason)
End Sub
It should connect.
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
I don't think I ever tried java 8 when I encountered the problem described in the thread linked to in post #1 here.
I've tried it briefly now and with the test/example apps I attached back then, using java 8 the secure websocket connects first time every time I tried it!

So, for me:
java 8 & jServer3 = wss connects reliably
java 11+ & jServer3 = wss does not connect reliably but does eventually after a few retires
java 11+ & jServer4 = wss does not connect reliably but does eventually after a few retires.

As you say, @Alexander Stolte, it's strange!

Unfortunately I can't use java 8 in my case so I'm just dealing with the fact that it takes the secure websocket a few retries to connect.
I guess something changed between java 8 & 11 that we're missing. It would be lovely to know what it is, so if anyone figures it out please post the solution!
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…