I always get this message TextMessage Error: (NumberFormatException) java.lang.NumberFormatException: For input string: "success"
when i receive follwoing data from webserver side {"prop":"StartOrStop","etype":"runFunction","value":["stop",1]}
b4j = v9.1 , json = v1.2
webserver side code
webclient side code, EventName = wsh
when i receive follwoing data from webserver side {"prop":"StartOrStop","etype":"runFunction","value":["stop",1]}
b4j = v9.1 , json = v1.2
webserver side code
B4X:
' start or stop
Sub StartOrStop(eid As String,cmd As String) As Int
If Engine.Size<1 Then
Return -99
End If
If Not(Engine.ContainsKey(eid)) Then
Return -98
End If
Dim b1 As Boolean=IIf(cmd="start",True,False)
If Main.autostart And Not(b1) Then
Main.autostart = False
End If
Dim item As Map = Engine.Get(eid)
Dim ws1 As WebSocket=item.Get("ws")
Dim lst As List
lst.Initialize
lst.Add(cmd)
lst.Add(jyAuth.Authorizing)
ws1.RunFunction("StartOrStop",lst)
End Sub
webclient side code, EventName = wsh
B4X:
Private Sub ws_TextMessage(msg As String)
Try
' {"prop":"StartOrStop","etype":"runFunction","value":["start",3]}
Dim jp As JSONParser
jp.Initialize(msg)
Dim m As Map = jp.NextObject
Dim etype As String = m.get("etype")
Dim params As List = m.get("value")
Dim Event As String = m.get("prop")
If etype = "runFunction" Then
CallSub2(CallBack, EventName & "_" & Event, params) ==> wsh_StartOrStop(Params As List)
End If
Catch
Log("TextMessage Error: " & LastException)
Log(msg)
End Try
End Sub
Sub wsh_StartOrStop(Params As List)
If Params.Size <> 2 Then
wsengine.PostMsgLog($"StartOrStop.Param<>2"$)
Return
End If
Dim cmd As String = Params.Get(0)
Dim n1 As Int = engine.StartOrStop(cmd)
wsengine.Authorizing = Params.Get(1)
If wsengine.Authorizing >= 0 Then
cdt.Enabled = False
Else
If cmd.ToLowerCase="start" Then
wsengine.PostWarLog($"Each start is limited to 2 hours and the timing starts"$)
cdt.Enabled = True
Else
cdt.Enabled=False
End If
End If
cdn = 2*60*60
wsengine.PostMsgLog($"StartOrStop.${Params.Get(0)} = ${jylab.IIF2(n1=1,"success","fail")}"$)
End Sub
Last edited: