B4J Question Web socket client SSL can't connect

EvgenyB4A

Active Member
Licensed User
Longtime User
I have a program that works fine with non secure link to server.
When I try to connect to wss link the connection process lasts about 1 minute and then throws following:

org.eclipse.jetty.websocket.api.UpgradeException: 0 null ....
''''''''''''''''''''
'''''''''''''''''''
WebSocket Closed: 0 null


I can succeed to connect to the same link with BrowserWebSocket Clent extension.
 

EvgenyB4A

Active Member
Licensed User
Longtime User
I need to clarify.
Now I work with web socket client and need to connect it to server with secure connection.
I use an extension to check the link and server if it accepts connections.

Is there any B4J websocket client Ssl example that I can connect to the link you sent me?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I have a program that works fine with non secure link to server.
When I try to connect to wss link the connection process lasts about 1 minute and then throws following:

org.eclipse.jetty.websocket.api.UpgradeException: 0 null ....
''''''''''''''''''''
'''''''''''''''''''
WebSocket Closed: 0 null
I can succeed to connect to the same link with BrowserWebSocket Clent extension.
You need a SslContextFactory instance to verify the certificate. try the code below:
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)
   ws.Connect("wss://yourdomanin/...")
   Wait For ws_Connected
   Log("connected")
 
Last edited:
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
You need a SslContextFactory instance to verify the certificate. try the code below:
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)
   ws.Connect("wss://yourdomanin/...")
   Wait For ws_Connected
   Log("connected")
Unfortunately, I didn't succeed. Can you send example with link you can connect wss?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Unfortunately, I didn't succeed. Can you send example with link you can connect wss?
The example is attached, it can connect to wss://b4x.com:51041/smiley/ws
 

Attachments

  • wssconnection.zip
    2.1 KB · Views: 120
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
The example is attached, it can connect to wss://b4x.com:51041/smiley/ws
Unfortunately, not succeeded.
After about 30 seconds after "Click Me":

Waiting for debugger to connect...
Program started.
2023-07-24 06:41:29.489:INFO::JavaFX Application Thread: Logging initialized @3578ms 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@448d137a(l:/192.168.113.154:50995 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@638e2d52(exchange=HttpExchange@5c5631fa req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@a8a4a87(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@35d9f434{s=START}],recv=HttpReceiverOverHTTP@272fab60(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<-DecryptedEndPoint@3231dec3{b4x.com/67.227.218.133:51041<->/192.168.113.154:50995,OPEN,fill=-,flush=-,to=6/0}->HttpConnectionOverHTTP@448d137a(l:/192.168.113.154:50995 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@638e2d52(exchange=HttpExchange@5c5631fa req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@a8a4a87(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@35d9f434{s=START}],recv=HttpReceiverOverHTTP@272fab60(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]->SocketChannelEndPoint@2480987c{b4x.com/67.227.218.133:51041<->/192.168.113.154:50995,ISHUT,fill=-,flush=-,to=7/0}{io=0/0,kio=0,kro=1}->SslConnection@5ff77226{NEED_WRAP,eio=-1/-1,di=-1}=>HttpConnectionOverHTTP@448d137a(l:/192.168.113.154:50995 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@638e2d52(exchange=HttpExchange@5c5631fa req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@a8a4a87(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@35d9f434{s=START}],recv=HttpReceiverOverHTTP@272fab60(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]
... 13 more
org.eclipse.jetty.websocket.api.UpgradeException: 0 null

Chrome extension succeeds to connect to this link.
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
Try to deploy a local ssl server for the testing
It will be the problem. Need arrange certificate.
But what may be the problem If from the same PC by another client the connection is being established?
If there another websocket client library on B4J?
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
and got occasionly 2 times succes
Assuming everything was the same on each attempt, the fact you got a connection OK twice would suggest to me that your connection details & certificate are OK.

Try the suggestions from @OliverA and @Erel in posts #2 & #3 of the thread I linked to.

I use B4J v9.30.
Updating to the latest version can't harm as well.
 
Last edited:
Upvote 0
Top