简体   繁体   English

让我局域网中的主机在特定端口上侦听

[英]get hosts in my LAN listening on a specific port

I am developing a network game in C under Linux, so the users in the LAN can play with each other. 我正在Linux下用C开发网络游戏,因此LAN中的用户可以互相玩耍。 Therefore a server is running in each host, listening in a specific port. 因此,服务器在每个主机中运行,并在特定端口上侦听。

So a client must realize a scanning of all the hosts in the same LAN listening the port. 因此,客户端必须实现对同一局域网中侦听端口的所有主机的扫描。 I could use nmap, but nmap will yield too much information that I will have to compute with a pipe, isn't it?? 我可以使用nmap,但是nmap会产生过多的信息,我必须使用管道来计算,不是吗?

Please, let me know if you think the following idea is suitable. 请让我知道您是否认为以下想法合适。

If I knew my own IP address, I would know the type of IP address, AB or C, and also I would know the part of the IP aimed for hosts. 如果我知道自己的IP地址,那么我会知道IP地址的类型,AB或C,也知道用于主机的IP部分。 So using the socket system call “connect” to the specified port I am able to know all the hosts in my network offering this service. 因此,使用套接字系统调用“连接”到指定的端口,我就能知道网络中提供此服务的所有主机。

What do you think is better?? 您认为哪个更好??

Thank you very much!!! 非常感谢你!!!

make a broadcast with your own ip in it and let the others response to you with theirs ip, so simple. 使用自己的IP进行广播,让其他人使用自己的IP对您做出响应,非常简单。 you could use avahi (zeroconf) for this. 您可以为此使用avahi(zeroconf)。

Use broadcast or multicast-multicast is a special type of broadcasting data only to interested clients. 使用广播或多播-多播是仅向感兴趣的客户端广播数据的一种特殊类型。 Check it out here: http://www.ibiblio.org/pub/linux/docs/howto/other-formats/html_single/Multicast-HOWTO.html 在此处查看: http : //www.ibiblio.org/pub/linux/docs/howto/other-formats/html_single/Multicast-HOWTO.html

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

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