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

 

Chris2

Active Member
Licensed User
Longtime User
I'm not sure if this is the issue but....
Make sure you're using the latest version of jWebsocketClient:

And then update your accept all trust manager code to:
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
Thanks for your help

But now I have this error immidiatilly
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
Do NOT use Images for a crashlog! Please post them as text as it is text which you can copy.
Sorry
But with this image you can see that line 46 is highlighted.
See below the raw text

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")

    'code om te proberen
    ws.Initialize("ws")
    SetAcceptAll(ws)
    ws.Connect("wss://ws.postman-echo.com/raw")
    Wait For ws_Connected
    Log("connected")



End Sub
Private Sub SetAcceptAll (WebSocket As WebSocketClient)
    Dim ssl As JavaObject
    ssl.InitializeNewInstance("org.eclipse.jetty.util.ssl.SslContextFactory.Client", Array(True))
    Dim ClientConnector As JavaObject
    ClientConnector.InitializeNewInstance("org.eclipse.jetty.io.ClientConnector", Null)
    ClientConnector.RunMethod("setSslContextFactory", Array(ssl))
    Dim Infos As JavaObject
    Infos.InitializeArray("org.eclipse.jetty.io.ClientConnectionFactory$Info", Array())
    Dim HttpTransport As JavaObject
    HttpTransport.InitializeNewInstance("org.eclipse.jetty.client.dynamic.HttpClientTransportDynamic", Array(ClientConnector, Infos))
    Dim HttpClient As JavaObject
    HttpClient.InitializeNewInstance("org.eclipse.jetty.client.HttpClient", Array(HttpTransport))
    Dim jo As JavaObject = WebSocket
    Dim wsc As JavaObject
    wsc.InitializeNewInstance("org.eclipse.jetty.websocket.client.WebSocketClient", Array(HttpClient))
    jo.SetField("wsc", wsc)
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
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…