1

我正在开发一个使用 UDP 进行通信的多客户端/单服务器应用程序。原因是我正在使用多播并且正在流式传输音频。

我在 UDP/TCP 方面没有很多经验,我不确定我是否可以使用多个DatagramSockets具有多个不同端口的多个端口。我有几个不同的对象需要从一个设备发送到另一个设备,因此我为每种类型的对象使用一个端口。

这个可以吗?我现在已经在使用大约 7 个不同的端口。如何使用尽可能少的端口?

4

1 回答 1

1

With multiple clients and one server, you could have all clients send data to the same port on the server. The server would read all information from one socket (which is reading data on that port). Each client that sends data can send metadata along with each payload identifying the user, so the server can discern which received packet belongs to who. I actually think that you can already see the address that a packet comes from using built in functionality however. You could use these addresses to identify different clients, however down the road you might need a more robust solution to make your implementation more secure.

于 2012-11-21T23:17:42.353 回答