B4J Question [JwebsocketClient] + [ Jserver ] are both incompatible in the same project?

Waldemar Lima

Well-Known Member
Licensed User
i am trying to connect on a websocket using websocket client so that the Jserver web server can provide the website . are both incompatible?

Code Module I'm trying to use >
B4X:
Sub Process_Globals
    Private wsc As WebSocketClient
End Sub

Sub InitWsConnection
    
    wsc.Initialize("wsc")
    wsc.Connect("wss://ws.xxxxxxxx.xxx/function")
    
End Sub

Sub wsc_Connected
    Log("Conected bro")
End Sub

when calling >: wsc.Initialize("wsc"), I immediately get the error below:
B4X:
2022-12-20 20:37:45.142:INFO :oejs.Server:main: jetty-11.0.9; built: 2022-03-30T17:44:47.085Z; git: 243a48a658a183130a8c8de353178d154ca04f04; jvm 11.0.1+13
2022-12-20 20:37:45.216:INFO :oejss.DefaultSessionIdManager:main: Session workerName=node0
2022-12-20 20:37:45.225:INFO :oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@29e495ff{/,file:///C:/Users/skink/OneDrive/Documentos/Projetos/myapp1\app1Server/Objects/www/,AVAILABLE}
2022-12-20 20:37:45.241:INFO :oejs.RequestLogWriter:main: Opened C:\Users\skink\OneDrive\Documentos\Projetos\myapp1\app1Server\Objects\logs\b4j-2022_12_20.request.log
2022-12-20 20:37:45.367:INFO :oejs.AbstractConnector:main: Started ServerConnector@5f71c76a{HTTP/1.1, (http/1.1)}{0.0.0.0:51042}
2022-12-20 20:37:45.384:INFO :oejs.Server:main: Started Server@5ccddd20{STARTING}[11.0.9,sto=0] @478ms
mywsmodule._initwsconnection (java line: 30)
java.lang.InstantiationError: org.eclipse.jetty.util.ssl.SslContextFactory
    at org.eclipse.jetty.websocket.client.DefaultHttpClientProvider.newHttpClient(DefaultHttpClientProvider.java:43)
    at org.eclipse.jetty.websocket.client.HttpClientProvider.get(HttpClientProvider.java:49)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:90)
    at anywhersoftware.b4j.objects.WebSocketClientWrapper.Initialize(WebSocketClientWrapper.java:56)
    at b4j.example.mywsmodule._initwsconnection(mywsmodule.java:30)
    at b4j.example.main._appstart(main.java:55)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:28)
main.main (java line: 28)
java.lang.RuntimeException: java.lang.InstantiationError: org.eclipse.jetty.util.ssl.SslContextFactory
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:28)
Caused by: java.lang.InstantiationError: org.eclipse.jetty.util.ssl.SslContextFactory
    at org.eclipse.jetty.websocket.client.DefaultHttpClientProvider.newHttpClient(DefaultHttpClientProvider.java:43)
    at org.eclipse.jetty.websocket.client.HttpClientProvider.get(HttpClientProvider.java:49)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:90)
    at anywhersoftware.b4j.objects.WebSocketClientWrapper.Initialize(WebSocketClientWrapper.java:56)
    at b4j.example.mywsmodule._initwsconnection(mywsmodule.java:30)
    at b4j.example.main._appstart(main.java:55)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 2 more
initializing client
connected
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I don't think that's the issue, the issue is an SSL error. So may be the page you are trying to connect doesn't have SSL or it's SSL has some issue.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
did you try connecting using "ws" instead of "wss":

wsc.Connect("ws://ws.xxxxxxxx.xxx/function")

so you can connect without SSL?
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
did you try connecting using "ws" instead of "wss":

wsc.Connect("ws://ws.xxxxxxxx.xxx/function")

so you can connect without SSL?
but if I comment out the line: wsc.Connect("ws:// ...
the error still pops up immediately .

1671594056652.png
 
Upvote 0
Top