Feature: Allow simulating outbound networking #579
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.
Summary
This PR allows simulating packet loss and delay of outbound packets in addition to the existing inbound latency & loss.
It also adds a new SIMULATE_NETWORK compiler flag that enables network latency and packet loss simulation features in release builds, providing an alternative to requiring DEBUG mode.
Background
We need to be able to test packet loss from the client to the server, and doing this per client is practical compared to setting simulation delay/loss on the server (which applies to all clients).
We are also building internal release builds in Unity and want the ability to simulate latency and packet loss in these builds. Being able to add this debug code without defining DEBUG seems practical and powerful.
Implementation
I have hooked into
NetManager.SendRaw
to allow dropped/delayed packets to respect resending etc.Thanks again for a great library!
Edit:
I have cleaned up the initial version and changed simulated latency to apply half the value on outbound and half on inbound packets. This way, a server will correctly interpret the client as being 1/2 Round Trip away, and the total latency remains backwards compatible.