B4J Question WSS connection failed

jayel

Active Member
Licensed User
Longtime User
Hello

I tried this testcode :

test wss:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private ws As WebSocketClient
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
    ws.Initialize("ws")
    'accept all trust manager
    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://b4x.com:51041/smiley/ws")
    'ws.Connect("wss://192.168.4.139:17481")
    Wait For ws_Connected
    Log("connected")
End Sub

'Template version: B4J-1.0
#Region Delegates
Sub MainForm_FocusChanged (HasFocus As Boolean)
    B4XPages.Delegate.MainForm_FocusChanged(HasFocus)
End Sub

Sub MainForm_Resize (Width As Double, Height As Double)
    B4XPages.Delegate.MainForm_Resize(Width, Height)
End Sub

Sub MainForm_Closed
    B4XPages.Delegate.MainForm_Closed
End Sub

Sub MainForm_CloseRequest (EventData As Event)
    B4XPages.Delegate.MainForm_CloseRequest(EventData)
End Sub

Public Sub MainForm_IconifiedChanged (Iconified As Boolean)
    B4XPages.Delegate.MainForm_IconifiedChanged(Iconified)
End Sub
#End Region

But have errors... see below

Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
2023-12-19 11:49:43.870:INFO::JavaFX Application Thread: Logging initialized @732ms 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.lang.Thread.run(Thread.java:750)
Caused by: java.io.EOFException: HttpConnectionOverHTTP@265b55bf(l:/192.168.19.20:40450 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@3ca366cf(exchange=HttpExchange@3a22b50 req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@d551e1c(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@7bbe0d26{s=START}],recv=HttpReceiverOverHTTP@5c8c9980(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]<-DecryptedEndPoint@60ba64b3{b4x.com/67.227.218.133:51041<->/192.168.19.20:40450,OPEN,fill=-,flush=-,to=1/0}->HttpConnectionOverHTTP@265b55bf(l:/192.168.19.20:40450 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@3ca366cf(exchange=HttpExchange@3a22b50 req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@d551e1c(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@7bbe0d26{s=START}],recv=HttpReceiverOverHTTP@5c8c9980(rsp=IDLE,failure=null)[HttpParser{s=CLOSED,0 of -1}]]->SocketChannelEndPoint@58c2a1bd{b4x.com/67.227.218.133:51041<->/192.168.19.20:40450,ISHUT,fill=-,flush=-,to=2/0}{io=0/0,kio=0,kro=1}->SslConnection@20d342de{NEED_WRAP,eio=-1/-1,di=-1}=>HttpConnectionOverHTTP@265b55bf(l:/192.168.19.20:40450 <-> r:b4x.com/67.227.218.133:51041,closed=false)=>HttpChannelOverHTTP@3ca366cf(exchange=HttpExchange@3a22b50 req=TERMINATED/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@d551e1c(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@7bbe0d26{s=START}],recv=HttpReceiverOverHTTP@5c8c9980(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)
 

OliverA

Expert
Licensed User
Longtime User
I still don't get it to work, this sample, simple program !
The code from the jWebSocketClient v2 accept all certificates post works right out of the box for me.
Same here
I'd suggest you export your app as a zip file (Filemenu>Export As Zip) and post the zip here.
That would have been truly helpful from the beginning, since we may be chasing ghosts here.

Note: I've just updated B4J from 10 beta#2 to the release. I already have JDK 11 and 14 installed (all provided from b4x.com's site using the instructions from b4x.com. The example (after copying the source above to a new project - again, a posted project would have been simpler), updating the internal library folder (in my case C:\Program Files\Anywhere Software\B4J\Libraries) and the internal jserver folder (in my case C:\Program Files\Anywhere Software\B4J\Libraries\jserver) AND refreshing the libraries in the Libraries tab of the IDE, the sample compiled without issues and ran without issues.

Here's the app's log output:
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
2023-12-20 07:33:34.297:WARN :eek:ejusS.config:Thread-3: Trusting all certificates configured for Client@1ed4f3e5[provider=null,keyStore=null,trustStore=null]
2023-12-20 07:33:34.300:WARN :eek:ejusS.config:Thread-3: No Client EndPointIdentificationAlgorithm configured for Client@1ed4f3e5[provider=null,keyStore=null,trustStore=null]
connected
 
Upvote 0
Top