2

Hi I'm wondering how to set up UDPClients to enable real-time 2 way communication between clients

I'm working on a simple network game in C#, it should be possible for a player to host a game and for others to connect to it

The host will send out the new game state every X millisecond and will simultaneously be receiving a continuous stream of user input from the other players

The other players will constantly be waiting for new input states and also be sending out user input to the host

What I'm wondering is how to achieve this.

Should I be using 2 different UDPClients, isn't there a potential thread conflict if they try to utilize the same resource at the same time? If not, do i need to set them up in some special way, else if I'm using 1 UDPClient, is there anything special i need to account for or is it thread safe and i can just fire away new messages while receiving?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user25470
  • 585
  • 4
  • 17

1 Answers1

1

UDP is a duplex protocol (like TCP).

You can safely send and receive off the UDPClient object at the same time. You should not use two UDPClient objects.

However, those operations do occur on separate threads (or pseudo-threads, if you use await/async), so you may run into synchronization issues in the calling code (obviously its hard to say without seeing it, but the potential is there).

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117