Exercise: Fastest Server Matchmaking
Problem statement
In multiplayer gaming, a client must often ping multiple regional matchmaking servers simultaneously to determine which one offers the lowest latency. You need to implement a utility that simulates pinging three servers and automatically selects the one that responds first, allowing the player to connect without waiting for the slower servers.
Task requirements
Start the simulated ping process for three regions: “US-East”, “Europe”, and “Asia”.
Determine which server responds first.
Extract and return the name of the winning server from the utility class.
Constraints
You must use
Task.WhenAnyinside theMatchmakerclass to race the three tasks against each other.You must
awaitthe winning task to extract its string result.Do not block the thread using
.Resultor.Wait().
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Pass the three tasks into
Task.WhenAnyseparated by commas insideFindFastestServerAsync.Task.WhenAnyreturns aTask<Task<string>>. The firstawaitgives you the winningTask<string>.You need a second
awaitto get the actualstringvalue from the winning task, which you then return.
Exercise: Fastest Server Matchmaking
Problem statement
In multiplayer gaming, a client must often ping multiple regional matchmaking servers simultaneously to determine which one offers the lowest latency. You need to implement a utility that simulates pinging three servers and automatically selects the one that responds first, allowing the player to connect without waiting for the slower servers.
Task requirements
Start the simulated ping process for three regions: “US-East”, “Europe”, and “Asia”.
Determine which server responds first.
Extract and return the name of the winning server from the utility class.
Constraints
You must use
Task.WhenAnyinside theMatchmakerclass to race the three tasks against each other.You must
awaitthe winning task to extract its string result.Do not block the thread using
.Resultor.Wait().
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Pass the three tasks into
Task.WhenAnyseparated by commas insideFindFastestServerAsync.Task.WhenAnyreturns aTask<Task<string>>. The firstawaitgives you the winningTask<string>.You need a second
awaitto get the actualstringvalue from the winning task, which you then return.