0

I'm using UDP for a game that I am making, but this issue is not nescessarily game-specific. I have noticed that whenever I want to test something locally and I use broadcasting, there's a chance that the UDP client sending some data out is also the same client receiving it again, instead of the other client also connected from the same machine.

How can I test and debug this effectively on one machine, simulating it in used condition on two machines?

Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187

2 Answers2

3

Two options:

  1. Use a different port for each direction of traffic, e.g. client -> server is port 2001, server -> client is port 2002.
  2. Use a virtual machine. You can use VirtualBox or VMWare to set up a virtual OS, complete with network cards.

The latter option will not require you to change your code, but you'll need to copy the server or client application to the VM every time you change the code.

Polynomial
  • 27,674
  • 12
  • 80
  • 107
1

Don't you use some kind of identifier (username or id) to detect who sent the original message?

Check if a received message is sent from the same identifier as the receiver has, and if so, discard the message.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272