你如何发现一个的TCPListener服务的名称IP地址? [英] How do you discover a TCPListener Service's IPaddress?

查看:101
本文介绍了你如何发现一个的TCPListener服务的名称IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从另一台计算机在局域网上发送消息到的TcpListener服务,您需要知道服务器的IP地址和端口。因为你可能选定的,但如果IP地址可能会有所不同,有一些方法你可以发现IP地址的端口是最有可能已经知道。

When sending messages to a TcpListener service from another machine on the LAN, you need to know the servers ip address and port. The port is most likely already known because you probably selected it but if the IP address can vary, is there some way you can discover the ip address.

在我看来,你需要让这些信息可通过完全另一种方法的发件人。

It seems to me that you need to make this info available to a sender via another method altogether.

推荐答案

要做到这一点的方法之一是使用UDP多播。

One way to accomplish this is to use UDP multicast.

基本上,你把所有的应用程序监听一个众所周知的(预先确定的,当然)多播IP地址和端口。每个主机然后广播到该地址,并包括用于制造在邮件正文中的TCP连接它们的TCP IP和端口。如果它是一个游戏大厅系统,你也可以加入总的玩家,需要多少,等数量的信息。

Basically, you have all your applications listen on a well-known (pre-determined of course) multicast IP and port. Each host then broadcasts to this address and includes their TCP IP and port for making the TCP connection in the message body. If its a game lobby system, you can also include information like the number of total players, how many are needed, etc.

请注意,您控制广播的频率,当我做1000毫秒这个轮询间隔证明是足够了,但你可以将其设置为任何你想要的(基于局域网的价格,包大小等。)

Note that you control the frequency of the broadcast, when I did this a poll interval of 1000ms proved sufficient, but you can set it to whatever you want (based on your LAN rates, size of packets, etc.)

UdpClient.JoinMulticastGroup在 MSDN

UdpClient.JoinMulticastGroup on MSDN

你应该知道一件事,多播IP范围是:

One more thing you should know, the multicast IP range is:

多播地址范围是224.0.0.0到239.255.255.255。

The multicast address range is 224.0.0.0 to 239.255.255.255.

的Technet

有关某些原因,信息ISN 'T超级容易找到:)

For some reason that information isn't super easy to find :)

这篇关于你如何发现一个的TCPListener服务的名称IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆