B4J Question WebSocketException

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi
my no-ui b4j app use one jwebsocketclient(1.11) to connect abmaterial v4.30. it run ok but Every other time I always get following exception : :eek: and then exit application !

B4X:
Proc.Error(1): 2020-12-09 09:52:23.756:INFO::main: Logging initialized @214ms to org.eclipse.jetty.util.log.StdErrLog
main._appstart (java line: 102)
java.lang.RuntimeException: org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSING], expecting [OPEN or CONNECTED]
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
    at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
    at b4j.example.main._appstart(main.java:102)
    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:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:28)
Caused by: org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSING], expecting [OPEN or CONNECTED]
    at org.eclipse.jetty.websocket.common.WebSocketSession.getRemote(WebSocketSession.java:411)
    at anywhersoftware.b4j.objects.WebSocketClientWrapper.SendText(WebSocketClientWrapper.java:123)
    at b4j.example.websockethandler._sendeventtoserver(websockethandler.java:96)
    at b4j.example.wsengine._updateprofile(wsengine.java:175)
    at b4j.example.wsengine._timer1_tick(wsengine.java:166)
    at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
following code is abmaterila /server websocke
B4X:
'WebSocket class
Sub Class_Globals
    Public ws     As WebSocket
    Private eid As String
End Sub

Public Sub Initialize
    eid=""
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
    Log("engine connected. "&ws.UpgradeRequest.RequestURI)
    Dim s1 As String=MyDB.Substring(ws.UpgradeRequest.RequestURI,"/ws/engine/").Replace("/",",").Replace("\",",")
    Dim ss() As String=Regex.Split(",",s1)
    If ss.Length=2 And IsNumber(ss(1)) Then
        Dim n1 As Int=ss(1)
        wsengine.AddEngine(ss(0),n1, ws)
        MyDB.PostMsgLog($"connect engine(${n1}). ${ss(0)}"$)
    End If
End Sub

Private Sub WebSocket_Disconnected
    Log("engine disconnected")
End Sub

private Sub engine_msg(param As Map)
    Dim function1 As String=param.Get("function")
    Dim msg1 As String=param.Get("msg")
    CallSubDelayed2(MyDB,function1,msg1)
End Sub

private Sub engine_profile(param As Map)
    Dim s1 As String=param.Get("eid")
    If wsengine.EngineContains(s1) Then
        Dim mp1 As Map     = wsengine.EngineGet(s1)
        Dim sn As Int    = param.Get("sn")
        mp1.Put("Beating",param.Get("Beating")) 
        mp1.Put("started",param.Get("started"))
    End If
    'Log("profile")
End Sub

private Sub Device_Ping(param As Map)
    Log("Engine ping")
End Sub
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top