Android Question WebSocket problem

giada

Member
Sometimes i find difference between wsh.ws.connected and the real webs state...

I have 2 webs : 1 always open for rx
1 open only for tx and then closed

For both sometimes i find wsh.ws.connected = true but is not real so if i wsh.SendEventToServer it is not send and i can't understand to call wsh.connect
And diffrently if i call wsh.connect and the wsh is already connected i have a crash....

I've tried different way but i don't resolve it.

This is what i find in the log:

...
13/05/21 11:08:56_367 =====================Messaggio ricevuto via websocket: {"mitt":"Toso123456","dest":"000005","cop":"3","room":"videomed.beghelli.it_becar000005_1900","testo":"toso rispondi sono admin1","play":"si","progr":"28","rispondi":"si"}
13/05/21 11:08:56_369 rx messaggio
13/05/21 11:08:56_466 Analisi msg ricevuto
13/05/21 11:08:56_468 Ricevuta richiesta videocall da Toso123456
(WEBS RX OK)
(NOW I TRY TO TX ON WEBSTX)
13/05/21 11:08:56_470 servizio webs_tx già attivo
13/05/21 11:08:56_471 timer webstx già inizializzato
13/05/21 11:08:56_473 schermo intero
13/05/21 11:08:56_574 stato automa timerWebSTx_Tick: 0
13/05/21 11:08:56_575 stato wshTx: false
13/05/21 11:08:57_077 stato automa timerWebSTx_Tick: 1
13/05/21 11:08:57_078 stato wshTx: false
13/05/21 11:08:57_358 TextToSpeechFinish
13/05/21 11:08:57_580 stato automa timerWebSTx_Tick: 0
13/05/21 11:08:57_582 stato wshTx: false
13/05/21 11:08:57_648 ws_Closed: Could not connect to WebSocket server
13/05/21 11:08:57_650 wshTx_Closed Could not connect to WebSocket server
13/05/21 11:08:58_085 stato automa timerWebSTx_Tick: 1
13/05/21 11:08:58_087 stato wshTx: true (HOW IT'S POSSIBLE??????????????????????????????????????????????????????????????????????)
13/05/21 11:08:58_088 Trasmetto Messaggio 000005 Toso123456 1 (MyMap) {} (HERE SendEventToServer BUT THE WEBS IS NOT OPEN)

13/05/21 11:08:58_590 stato automa timerWebSTx_Tick: 3
13/05/21 11:08:58_591 stato wshTx: true
13/05/21 11:08:58_592 stato wshTx: true
13/05/21 11:08:59_632 Controllo appuntamenti
13/05/21 11:09:01_807 =====================Messaggio ricevuto via websocket: {"mitt":"Toso123456","dest":"000005","cop":"3","room":"videomed.beghelli.it_becar000005_1900","testo":"toso rispondi sono admin1","play":"si","progr":"28","rispondi":"si"}
13/05/21 11:09:01_809 rx messaggio
13/05/21 11:09:01_979 Analisi msg ricevuto
13/05/21 11:09:01_981 Ricevuta richiesta videocall da Toso123456
13/05/21 11:09:01_983 servizio webs_rx già attivo
13/05/21 11:09:01_984 timer websRx già inizializzato
13/05/21 11:09:01_986 schermo intero
13/05/21 11:09:02_085 stato automa timerWebSTx_Tick: 0
13/05/21 11:09:02_086 stato wshTx: true
13/05/21 11:09:02_588 stato automa timerWebSTx_Tick: 1
13/05/21 11:09:02_590 stato wshTx: true
13/05/21 11:09:02_592 Trasmetto Messaggio 000005 Toso123456 1 (MyMap) {}

I attach my WebSocket File
 

Attachments

  • WebSocket.bas
    26.4 KB · Views: 140

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code is too large for me to say anything about it.

1. Make sure to use the latest version (2.11).
2. I've checked the library code. It should report the correct state, assuming that the network driver reports it correctly.

It is possible that you are seeing an intermittent state where the Closed event was raised but the internal socket is still connected.
Try it with:
B4X:
Log(wsh.ws.connected)
Sleep(100)
Log(wsh.ws.connected)
 
Upvote 0
Top