I can runfunction to client.
when I use SendEventToServer in the client(b4j app) Why server side always give me Runtime Exception:Invilid event name : fromclient1 ?
jserver V3.0
jwebsocketclient V1.10
client side code
server side code
when I use SendEventToServer in the client(b4j app) Why server side always give me Runtime Exception:Invilid event name : fromclient1 ?
jserver V3.0
jwebsocketclient V1.10
client side code
B4X:
Sub wsc_connected
Log($"gate connected. ${Main.gateaddr}"$)
SendEventToServer("fromclient1",CreateMap("test":1))
End Sub
Public Sub SendEventToServer(Event As String, Data As Map)
Dim m As Map
m.Initialize
m.Put("type", "event")
m.Put("event", Event)
m.Put("params", Data)
Dim jg As JSONGenerator
jg.Initialize(m)
wsc.SendText(jg.ToString)
End Sub
Private Sub wsc_TextMessage(msg As String)
Try
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(Me, "wsc_" & event, params)
Else If etype = "runFunctionWithResult" Then
Dim data As Map = CallSub2(Me, "wsc_" & event, params)
Dim jg As JSONGenerator
Dim m2 As Map : m2.Initialize
m2.Put("type", "data")
m2.Put("data", data)
jg.Initialize(m2)
wsc.SendText(jg.ToString)
End If
Catch
Log("TextMessage Error: " & LastException)
End Try
End Sub
B4X:
'WebSocket class
Sub Class_Globals
Private ws As WebSocket
Private item As Map
Private timer1 As Timer
End Sub
Public Sub Initialize
timer1.Initialize("timer1",500)
timer1.Enabled=False
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
ws = WebSocket1
Log($"Device connected. ${ws.UpgradeRequest.RemoteAddress}"$)
End Sub
Private Sub WebSocket_Disconnected
Log($"Device disconnected."$)
End Sub
Sub fromclient1(Params As Map)
Log("Device message: ")
End Sub
Last edited: