Replies: 3 comments 3 replies
-
So with tonic's channels and hyper's client its not possible to really detect when the tcp connection is disconnected unless you try to send a message and it fails (but usually it'll try to reconnect). What I would do instead is create a grpc streaming request. That will notify you when the client has disconnected via the incoming stream ending. |
Beta Was this translation helpful? Give feedback.
-
Couldn't you use a Tower middleware to run code after the stream ends? You could have the endpoint set a connection ID in an extension on the response, and have the middleware read that extension and clean up the map keys. |
Beta Was this translation helpful? Give feedback.
-
@LucioFranco are you basically saying to switch to bidirectional streaming from the client to the server? And then when @adamchalmers I'm not familiar with advanced tower middleware, is it possible to make a |
Beta Was this translation helpful? Give feedback.
-
I am implementing a turn-based game server using tonic. I use gRPC streaming for the game so that players get sent updates about the moves their opponents make once they connect, more or less like this (simplified):
The way I currently handle this is that I store a Sender object for each player that connects, so that I can update them later:
This way, when game actions come in, I can check the CHANNELS map to see which opponents are connected and send them an update with the new game state:
This approach is generally working quite well. One immediate problem, however, is that the CHANNELS map grows infinitely in size as players connect, I haven't been able to find an explicit callback in tonic when users disconnect from their gRPC streaming session where I could clean up the map. Does something like that exist? Alternatively, is this a complete misuse of the API and I should be doing something totally different? :)
(question mirrored with https://stackoverflow.com/questions/72841806)
Beta Was this translation helpful? Give feedback.
All reactions