I try to make a simple game using HTML5
, flask
and flask_socketio
(a flask extension of webSocket). I can connect all the player to the server, and return information to each (this is the easy part). My question is, When a player modifies something, how do I return personal information to each player (is not the same information for all)? This is possible?
Asked
Active
Viewed 18 times
0

F.N.B
- 1,539
- 6
- 23
- 39
1 Answers
0
Presumably you have some state in your server that allows you get a list of players, correct?
You need to add the socket.io session id to that state, so that you know how to address each player. So then to send updates to each player, you just iterate over them and send them their data. For example, something like this:
for player in all_the_players.keys():
emit('player_info', all_the_players[player], room=all_the_players[player]['sid'])
In this example, I have a global dict where the keys are the player names and the values are dicts with player specific data. One of the items in the player data is the sid
, which is used by Socket.IO to direct messages to specific clients.

Miguel Grinberg
- 65,299
- 14
- 133
- 152