Python-socketio: Python-socket.IO: how can i block ip address to connect

Created on 1 Feb 2018  路  9Comments  路  Source: miguelgrinberg/python-socketio

how i can block IP address to connect Python-Socket.IO server?

question

Most helpful comment

Well, yes, but you need to return False to kick the client out.

All 9 comments

what do you mean by "block" in this context? What are you trying to do?

I want to disconnect a client or kick client out of the connection
i have use:

server.manager.disconnect(sid, namespace)

The client is disconnected, But can emit a object again without connection again.

Do you have an example application that shows the problem?

Also, if you are doing this in the connect event handler, you can just return False if you want to kick the client out, no need to call disconnect.

default

Thank you. Did you mean that?

Well, yes, but you need to return False to kick the client out.

Ok thank you

@miguelgrinberg In the current release, how can I block the connect ? I tried the way mentioned above

from socketio.server import Server
@Server.on('connect', namespace=class_room_namespace)
def connect(sid, environ):
    print("connect============= ", sid,environ)

but failed as the on() method is not callable for Server class.
It throws 'TypeError: unbound method on() must be called with Server instance as first argument (got str instance instead)'

You need to create an instance of class Server and use on() on the instance.

This issue will be automatically closed due to being inactive for more than six months. Please reopen if you need more assistance.

Was this page helpful?
0 / 5 - 0 ratings