简体   繁体   English

C#让服务器看到IP上的客户端之间的区别:端口

[英]C# Have server see the difference between clients on IP:Port

So let's say I have a server on IP Address A. And two clients on IP Address B using software that is using the TcpClient class. 所以假设我在IP地址A上有一台服务器。在IP地址B上有两个客户端使用使用TcpClient类的软件。 If both clients are listening in two different IPv4 addresses but on the same port. 如果两个客户端都在侦听两个不同的IPv4地址但在同一端口上。 How will a server be able to reply with data to both of the clients using a TcpClient and a networkstream? 服务器如何使用TcpClient和网络流向两个客户端回复数据?

It's a bit difficult to try this for me at the moment considering I only have access to one computer at the moment and I can't have two tcplisteners on the same port on one computer. 考虑到目前我只能访问一台计算机并且我不能在一台计算机上的同一端口上安装两个tcplistener,这对我来说有点困难。

Thanks 谢谢

Edited for clarification. 编辑澄清。

First of all, only use one TcpListener, and do so in the server. 首先,只使用一个TcpListener,并在服务器中执行此操作。 The clients should connect to the server, not the other way around. 客户端应该连接到服务器,而不是相反。 This way, on the clients' computers, you'll be assigned a random available port to communicate with the server. 这样,在客户端的计算机上,您将被分配一个随机可用端口与服务器通信。

Second of all, you could use virtual machines to test on a single machine, or run the server and clients on the same computer, that would still work. 其次,您可以使用虚拟机在一台计算机上进行测试,或者在同一台计算机上运行服务器和客户端,这仍然有效。 Good luck! 祝好运!

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

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