1

Im trying to connect to the flask-socketio server, on const socket = io.connect(host); i get to print on the server log, but it doesnt emit back the function im trying to emit to client.

Client side code:

componentDidMount() {
        const socket = io.connect(host);
        console.log('testing', socket.connected);

        socket.on('connected', function(data) {
            console.log('listening connected...');
        });

        console.log('testing', socket.connected);
    }

server side code:

@socketio.on("connect")
def connectServer():
    print("Client connected")
    socketio.emit("connected")

logs on server side:

Client connected
192.168.56.1 - - [12/Dec/2019 18:25:53] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxb9l HTTP/1.1" 200 373 0.003000
192.168.56.1 - - [12/Dec/2019 18:25:53] "POST /socket.io/?EIO=3&transport=polling&t=MxwxbAA HTTP/1.1" 400 186 0.000000
Client connected
192.168.56.1 - - [12/Dec/2019 18:25:56] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxc2Y HTTP/1.1" 200 373 0.001000
192.168.56.1 - - [12/Dec/2019 18:25:56] "POST /socket.io/?EIO=3&transport=polling&t=Mxwxc31 HTTP/1.1" 400 186 0.001000
Client connected
192.168.56.1 - - [12/Dec/2019 18:26:00] "GET /socket.io/?EIO=3&transport=polling&t=Mxwxcxb HTTP/1.1" 200 373 0.002000
192.168.56.1 - - [12/Dec/2019 18:26:00] "POST /socket.io/?EIO=3&transport=polling&t=Mxwxcy6 HTTP/1.1" 400 186 0.000000

and client side console logs :

testing false
C:\OwnProjects\safetync\src\Screens\Authentication\signup.js:47 testing false

chrome console logs

UPDATE : this is what i get from engineio.logger = TRUE :-

Client connected
5ec1a26df0c245238439879c025ce05a: Client is gone, closing socket
5ec1a26df0c245238439879c025ce05a: Client is gone, closing socket
50a596f672014296b90befb5cf69d139: Sending packet MESSAGE data 2["connected","testign"]
a9b0114871554baea9cc33ea3637eccd: Sending packet MESSAGE data 2["connected","testign"]
0ddad6a7f8f6475ead11a8029ec04e0c: Sending packet MESSAGE data 2["connected","testign"]
6b42db33dded40e691ac074d2b0e08f3: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 2["connected","testign"]
2b862ce363da4a76a8dd09ec9c422a9e: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 0
192.168.56.1 - - [15/Dec/2019 13:22:23] "GET /socket.io/?EIO=3&transport=polling&t=My9Iucn HTTP/1.1" 200 378 0.009000
Invalid session None
192.168.56.1 - - [15/Dec/2019 13:22:23] "POST /socket.io/?EIO=3&transport=polling&t=My9IudU HTTP/1.1" 400 186 0.007000
d685108dd3fe441799ed1f1aec0de32e: Sending packet OPEN data {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': ['websocket'], 'sid': 'd685108dd3fe441799ed1f1aec0de32e'}
Client connected
50a596f672014296b90befb5cf69d139: Client is gone, closing socket
50a596f672014296b90befb5cf69d139: Client is gone, closing socket
a9b0114871554baea9cc33ea3637eccd: Sending packet MESSAGE data 2["connected","testign"]
0ddad6a7f8f6475ead11a8029ec04e0c: Sending packet MESSAGE data 2["connected","testign"]
6b42db33dded40e691ac074d2b0e08f3: Sending packet MESSAGE data 2["connected","testign"]
ccf27e3a769949f7bda025baf6101650: Sending packet MESSAGE data 2["connected","testign"]
d685108dd3fe441799ed1f1aec0de32e: Sending packet MESSAGE data 2["connected","testign"]
2b862ce363da4a76a8dd09ec9c422a9e: Sending packet MESSAGE data 2["connected","testign"]
d685108dd3fe441799ed1f1aec0de32e: Sending packet MESSAGE data 0
192.168.56.1 - - [15/Dec/2019 13:22:28] "GET /socket.io/?EIO=3&transport=polling&t=My9IvzR HTTP/1.1" 200 378 0.005000
Invalid session None
192.168.56.1 - - [15/Dec/2019 13:22:28] "POST /socket.io/?EIO=3&transport=polling&t=My9Ivzx HTTP/1.1" 400 186 0.001000
6f9d2c39e31a4cdb9f1c55a490772388: Sending packet OPEN data {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': ['websocket'],
  • You are getting a 400 error back from the server, so the server isn't happy about the way the server is handling the connection. You can enable additional logging on the server to have more information, add `engineio_logger=True` to your `SocketIO()` constructor. – Miguel Grinberg Dec 13 '19 at 11:16
  • @Miguel I know its a bad request error, I have updated question with logs. – Dennis Kumar Dec 15 '19 at 11:26
  • Your client is not passing a session in the POST request. Note that `Invalid session None` message. And I didn't notice this earlier, but now that I see the error, the POST request does not have the required `sid` argument. Unfortunately I cannot really help much, the client that you are using appears to be at fault. – Miguel Grinberg Dec 16 '19 at 00:07
  • @Miguel could you elaborate a bit more by what you mean that my client side is at fault? – Dennis Kumar Jan 15 '20 at 13:43
  • The requests that your client is sending do not agree with the Socket.IO protocol, they are missing information. You may want to see if you find a working example with this client, unfortunately I cannot give you advice as I'm not familiar with it, no idea how the React based client differs from the official JS one. – Miguel Grinberg Jan 16 '20 at 08:18

0 Answers0