Skip to content
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

Websocket Changes #86

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

nexus4880
Copy link
Contributor

Problem 1

Websocket connections could not poll to see if the connection was terminated by the client unless ReceiveAsync was called.

  • Each WsController, if utilizing while (context.IsOpen()) would need to call ReceiveAsync
  • If we want to match multiple controllers to a route in the future, only the first one would work

Solution: Move the burden of calling ReceiveAsync from the WsController to the WsRouter. It has been made internal and renamed to PollAsync so as not to be confused: it should NOT be called outside of WsRouter.

This places the responsibility of maintaining and managing the connection on the WsRouter instead of the WsControllers. This approach is also eh. In hindsight the HttpServer may have been best off owning and managing the state of the WsContext but it shouldn't be that big of a deal.


Problem 2

Because we are not fire and forgetting the controller's handle functions if a WsController runs a while loop for constant polling to check for data then the WsRouter will never continue.

Solution: Move to an event based system. The WsContext calls WsController.RunAsync which subscribes its callbacks to WsContext's events. This allows for us to override WsController.RunAsync in order to subscribe to only events that we need. By default all of them are subscribed.


I have done testing in and outside of the game, as well as making it so that I can relay notifications to my client from Postman. It is working exactly as I expected.

@nexus4880 nexus4880 changed the title Initial commit Websocket Changes Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant