Can you add the code where you initialize the connection?
Private Sub Connect
modUtils.LogSub("srvCommun", "Connect")
wsh.Initialize(Me, "wsh")
wsh.ws.Connect(Main.ServerLink)
End Sub
Are you sending any message from the client immediately after the connection? If yes then try to use CallSubDelayed in the client code to send the message only after the connection event.
Public Sub wsh_Connected
modUtils.LogSub("srvComm", "wsh_Connected")
Private mapData As Map : mapData.Initialize
mapData.Put("msg", "Hi, I'm connected")
wsh.SendEventToServer("RaisedByClient_Msg", mapData)
End Sub
Mmmmm... I checked your code.
When you start the service SrvCommun you chect the wsh websocket. If it is not initialized od not connected you call a Sub Connect.
B4X:Private Sub Connect modUtils.LogSub("srvCommun", "Connect") wsh.Initialize(Me, "wsh") wsh.ws.Connect(Main.ServerLink) End Sub
This sub performs wsh.ws.initialize (and set the callback) and then open the connection. But I think you shoud re-check the wsh.isInitialized status before the connect...
No, I didn't try. I don't use b4j (give me the compiled JAR file and I'll try)
"At first run wsh is surely not initialized" is exacly what I mean.
Actually you check if .Isinizialized and if not you Initialize the wsh.
But IMMEDIATELY after this call you try to open the connection...
My iphotesis: Initalize is performed by the WebSocket library, in another thred and therefore it could be asynchronous.
You are trying to connect wsh.ws.Connect(Main.ServerLink) an object that is still not initialized. The pointer to this object is currently NULL and it throws the exception.
Try to insert some delay between Initialize and connect, something like "Loop until wsh.IsInizialized"
The loop does not solve the problem and not even a pause of 3 seconds.
Ok, I'll install B4J in teh afternoon and I'll run then code.
- By the way, I'm not 'commandant' (at last Commander). I was Commander with Shado and now I'm retired. But you can call me 'Colonel'
Ehm, I'm sorry... you are allowed shoot me.
Given that other things were not working well, I was using the debug mode for the server.
Using the release, the problem does not exist.
Are you sending any message from the client immediately after the connection? If yes then try to use CallSubDelayed
Today I solved this problem, about 2.5 years after(I have not thought about this last 2.5 years ).
Reading again this post:
and doing some tests...
When the websocket (client) event Connected is raised the server websocket may not be really ready to receive data.
So the right way is:
the client opens the connection (as usual) but the first data transmitted MUST be ALWAYS sent by the server!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?