Links2004 / arduinoWebSockets

arduinoWebSockets
GNU Lesser General Public License v2.1
1.89k stars 556 forks source link

Could not connect ESP8266 SocketIO Client with Flask SocketIO Server #735

Open farrellhung opened 2 years ago

farrellhung commented 2 years ago

I am trying to use the example code for ESP8266 SocketIO Client to connect ESP with a Flask-SocketIO server, but got the following result:

with socketIO.send(sIOtype_CONNECT, "/"); :

15:31:12.028 -> [WS-Client] connect ws... 15:31:12.094 -> [WS-Client] connected to 192.168.43.77:5000. 15:31:12.094 -> [WS-Client][sendHeader] sending header... 15:31:12.094 -> [WS-Client][sendHeader] handshake GET /socket.io/?EIO=4&transport=polling HTTP/1.1 15:31:12.094 -> Host: 192.168.43.77:5000 15:31:12.127 -> Connection: keep-alive 15:31:12.127 -> Origin: file:// 15:31:12.127 -> User-Agent: arduino-WebSocket-Client 15:31:12.127 -> 15:31:12.127 -> [write] n: 157 t: 1893754 15:31:12.127 -> [WS-Client][sendHeader] sending header... Done (20439us). 15:31:12.127 -> ["logJSON",{"now":1893762}] 15:31:12.161 -> [WS-Client][handleHeader] RX: HTTP/1.0 200 OK 15:31:12.161 -> [WS-Client] connection lost. 15:31:12.161 -> [WS-Client] client disconnected. 15:31:12.194 -> [IOc] Disconnected! 15:31:12.194 -> [wsIOc] Disconnected!

without socketIO.send(sIOtype_CONNECT, "/"); :

15:36:46.555 -> [WS-Client] connect ws... 15:36:46.555 -> [hostByName] Host: 192.168.43.77 is a IP! 15:36:46.555 -> :ref 1 15:36:46.688 -> [WS-Client] connected to 192.168.43.77:5000. 15:36:46.688 -> [WS-Client][sendHeader] sending header... 15:36:46.721 -> [WS-Client][sendHeader] handshake GET /socket.io/?EIO=4&transport=polling HTTP/1.1 15:36:46.721 -> Host: 192.168.43.77:5000 15:36:46.721 -> Connection: keep-alive 15:36:46.721 -> Origin: file:// 15:36:46.721 -> User-Agent: arduino-WebSocket-Client 15:36:46.721 -> 15:36:46.721 -> [write] n: 157 t: 105283 15:36:46.721 -> :wr 157 0 15:36:46.721 -> :wrc 157 157 0 15:36:46.721 -> [WS-Client][sendHeader] sending header... Done (22737us). 15:36:46.787 -> :ack 157 15:36:46.787 -> :rn 17 15:36:46.787 -> :c0 1, 17 15:36:46.787 -> [WS-Client][handleHeader] RX: HTTP/1.0 200 OK 15:36:46.787 -> :rn 312 15:36:46.787 -> :rcl pb=0x3fff2994 sz=312 15:36:46.820 -> [WS-Client] connection lost. 15:36:46.820 -> :ur 1 15:36:46.820 -> :dsrcv 312 15:36:46.820 -> :close 15:36:46.820 -> :del 15:36:46.820 -> [WS-Client] client disconnected. 15:36:46.820 -> [IOc] Disconnected! 15:36:46.820 -> [wsIOc] Disconnected!

What I got from the server side:

WnvAXfIX_T9LbodiAAAA: Sending packet OPEN data {'sid': 'WnvAXfIX_T9LbodiAAAA', 'upgrades': ['websocket'], 'pingTimeout': 20000, 'pingInterval': 25000} 192.168.43.218 - - [22/Jan/2022 15:49:19] "GET /socket.io/?EIO=4&transport=polling HTTP/1.1" 200 - 2psb6EEmeE9-xcpoAAAB: Sending packet OPEN data {'sid': '2psb6EEmeE9-xcpoAAAB', 'upgrades': ['websocket'], 'pingTimeout': 20000, 'pingInterval': 25000} 192.168.43.218 - - [22/Jan/2022 15:49:20] "GET /socket.io/?EIO=4&transport=polling HTTP/1.1" 200 - VORJYzLMll0iqGeWAAAC: Sending packet OPEN data {'sid': 'VORJYzLMll0iqGeWAAAC', 'upgrades': ['websocket'], 'pingTimeout': 20000, 'pingInterval': 25000} 192.168.43.218 - - [22/Jan/2022 15:49:20] "GET /socket.io/?EIO=4&transport=polling HTTP/1.1" 200 -

Versions: flask-socketio-5.1.1 python-engineio-4.3.1 python-socketio-5.5.1 arduinoWebSockets 2.3.5 ESP8266 Arduino core 3.0.2

64n35h4 commented 2 years ago

Did you solve this issue? I'm having the same problem.

manulsan commented 2 years ago

I have same issues. ESP8266 try to make connection to "NodeJS socketIO Server".

ComanderKai77 commented 2 years ago

I've switched to

gunicorn==20.1.0 eventlet==0.30.2

and started my app with gunicorn -w 1 -k eventlet -b 127.0.0.1:5000 and now it works.