Use the Task-based asynchonous model#4
Open
JesHansen wants to merge 4 commits intomakeratplay:mainfrom
Open
Conversation
To use the Task based model for asynchronous communication, we need to update the framework version, so that we have access to the Task-based API for Sockets.
The StartListening method does three things: Sets up a localIP address, configures a socket, and start the listening. This change extracts the local IP setup into it's own method.
The Task based model enables us to use a more natural way to reason about the asynchronous part of the program. Previously the async parts were being done in two places, now all the async parts are in one place. The logic is also easier to grok: Listening for packets is done by looping around, parsing received data and exiting the loop once the socket is disposed.
makeratplay
approved these changes
Mar 21, 2024
Owner
makeratplay
left a comment
There was a problem hiding this comment.
Sorry it took so long to review this PR, but you know life happens. Changes look good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3
In this PR I've switched the asynchronous pattern from the old BeginX/EndX to the more modern Task-based API. The PR consists of a number of small commits so that it's easier to follow along. The PR consists of the following logical steps:
The logic behind how packets are processed is simpler as the async parts are now in a central place, instead of being spread across multiple methods. This allows us to use a simpler mental model of what is happening: Loop to receive packets, handle them as they arrive, shut down when the socket is closed.
I've tested that the app still runs, but async code is tricky; there could easily be something I've overlooked. Do test thouroughly before merging anyhing from the latest commit in this PR. Please let me know if you can spot any behaviour that changes due to this PR. :-)