简体   繁体   English

使用UDP测试多人客户端/服务器?

[英]Testing multiplayer client/server with UDP?

I'm using UDP for a game that I am making, but this issue is not nescessarily game-specific. 我正在为正在制作的游戏使用UDP,但是此问题不一定是特定于游戏的。 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. 我注意到,每当我要在本地测试某些内容并使用广播时,发送一些数据的UDP客户端就有可能是再次接收该数据的同一客户端,而不是其他也从同一台计算机连接的客户端。

How can I test and debug this effectively on one machine, simulating it in used condition on two machines? 如何在一台机器上有效地测试和调试它,并在两台机器上模拟使用状态?

Two options: 两种选择:

  1. Use a different port for each direction of traffic, eg client -> server is port 2001, server -> client is port 2002. 对每个流量方向使用不同的端口,例如, client -> server是端口2001, server -> client是端口2002。
  2. Use a virtual machine. 使用虚拟机。 You can use VirtualBox or VMWare to set up a virtual OS, complete with network cards. 您可以使用VirtualBox或VMWare来设置带有网卡的虚拟OS。

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. 后一种选项不需要您更改代码,但是每次更改代码时,都需要将服务器或客户端应用程序复制到VM。

Don't you use some kind of identifier (username or id) to detect who sent the original message? 您是否不使用某种标识符(用户名或ID)来检测谁发送了原始邮件?

Check if a received message is sent from the same identifier as the receiver has, and if so, discard the message. 检查接收到的消息是否从与接收者相同的标识符发送,如果是,则丢弃该消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM