Java Multicast / Broadcast Java中的网络发现 [英] Network discovery in Java Multicast/Broadcast Java

查看:153
本文介绍了Java Multicast / Broadcast Java中的网络发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在尝试做的事情 - 服务器向网络上的所有PC以及启动并运行的PC发送活动消息,通过发送其IP来响应呼叫。

Here's what I'm trying to do- A server sends out "Alive message to all the PCs on the network and the PCs which are up and running, respond to the call by sending their IP.

我正在寻找一个轻量级的编码,因为这将构成我应用程序的一小部分。

I'm looking at a lightweight piece of coding as this will form a small bit of my application.

我看过Jini和其他服务,但发现我可能不需要他们的一半功能(网络发现除外)

I've looked at Jini and other services but find that I may not need even half of their features(except for the network discovery)

如果我:
1可以。使用for循环,服务器打开套接字,检查(使用for循环)是否可以通过发送Alive消息来访问所有IP xxxx.
2.在客户端收到alive消息时特定套接字,客户端回复其IP。

Is it ok if I: 1. Use a for loop where a server opens a socket, checks(using a for loop) if all the IPs x.x.x.x are reachable by sending an "Alive" message. 2. On receiving the "alive" message at the client at the specific socket, the client replies with its IP.

这种方法可以吗?你认为我能以更好的方式做到这一点吗?

Is this method OK? Do you think I could do it in a better way?

谢谢!

推荐答案

很久以前我遇到过类似的问题,我解决了以下问题:

I had a similar problem a long time ago and I resolved it as follows:


  • s erver在网络上广播UDP数据包到255.255.255.255

  • 所有可到达的客户端都将使用包含其IP和您要发送的任何其他信息的UDP数据包进行响应。

我个人使用的数据包看起来像

The packet I personally used looks like

public class UDPDiscoveryPacket{
      public final long sendingTime;
      public final String clientIP;
      public UDPDiscoveryPacket(long sendingTime, String clientIP){
         this.sendingTime = sendingTime;
         this.clientIP = clientIP;
      }
}

这篇关于Java Multicast / Broadcast Java中的网络发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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