-
-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emitting to specific client #89
Comments
I made this gist and it seems to work. But I don't know if this approach is OK or if using it in production will create problems? |
@ericremoreynolds your solution will work just fine, but has the undesirable feature that you use
Hope this helps. |
Hi miguelgrinberg, i'm reading your example code about room, but when i press "send to room" button, nothing show up on my browser(i have already joined a room), can you please tell me how to deal with it? Thank you. |
@jeffjzx did you write a room name before clicking the join and send buttons? What name did you use? |
Oops, sorry, i realize that i have used the forms in wrong order. Thank you for your reply.. |
@miguelgrinberg, first of all: great repo -- thanks for building it. I think sending to an individual client out of context might be the most typical use case and I think the room work around is a bit limited: 1). It may be desirable not to force clients to authenticate? Also, since the socket itself has a unique identifier can't you expose that (like I believe the socket.io node library?) 2). The "room" workaround is going to "pollute" the set of rooms? Again the node implementation seems to have a more straight-forward API -- isn't something like this possible and natural? io.sockets.socket(savedSocketId).emit(...) Thanks, RB |
I don't understand what is the relation between user authentication and this. You can put clients into rooms without authenticating them.
You can certainly follow this approach if you like. But
The set of rooms is handled internally by the extension, so it should not affect you at all. The memory requirements for a room are fairly small. I find the node implementation less straightforward. You can address a message to a specific client (via its session ID), or to a room (via a room name) or to all clients (via For the upcoming major release of this extension I'm planning to automatically create the individual client rooms. These will be given the name of the session ID, which is exactly what you suggested above. |
I may not have understood, but in your answer above you say "Once the user is logged in, I write his/her ID to session"
Again, I probably have misunderstood but isn't the socket ID the "sessid" that is generated by the server (as requried by the protocol: https://github.com/socketio/engine.io-protocol)
Anyway:
Nice. Do you have an ETA? But, I still seem to have trouble with the current API: in my app the following line seems to unexpectedly do a broadcast (to unauthenticated apps in different chrome tabs):
Whereas the following line doesn't emit anything that is picked up by any client:
And finally (sorry) the socketio docs (http://socket.io/docs/) say that broadcast "means sending a message to everyone else except for the socket that starts it". That seems really odd to me (how could the server then initiate a message to everyone?) Does that explain what I'm seeing above (are you implementing the feature the same way). Thanks again. |
Closing this issue, as release 1.0 dropped gevent-socketio in favor of a new set of dependencies. |
Hello Miguel! Congratulation for your great project, FLASK! I have this small project described below and please tell me if it is suitable for testing / using Flask-SocketIO on server side. I have a temperature monitoring project, what i use some years ago. Here is a simplified BLOCK diagram: What I want to try it is to have a login option on the server side, and after successful login connect the the respective user to server localhost, port assigned by user ID. Please tell me if the Flask-SocketIO is the good choice above described requirements. Thank's in advance for your reply! |
Hello Miguel,
In the JavaScript socket.io server there are a couple of ways to emit to a specific client, even from outside of the client's context:
a) socket.emit
b) emit to the room named "Socket#id" where id is a unique client id
I was wondering how this can be achieved with Flask-socket.io? Would option (b) apply? If so how can I obtain the client id?
Best regards,
Eric
The text was updated successfully, but these errors were encountered: