如何在java网络中广播

发布于 2024-11-18 19:56:42 字数 186 浏览 3 评论 0原文

这是我第一次用java进行网络编程。 我正在寻找一种以某种方式向整个网络中的所有节点发送广播的方法。让他们知道我的存在。 我正在尝试制作一款多人网络游戏,我希望客户能够看到所有可用的游戏以选择加入哪一个。 我想知道如何从服务器广播以及如何让客户端收听。

请简单一点,我是新手:)

提前致谢。

Its my first time programing network in java.
I was looking for a way to send to somehow broadcast to all nodes in the whole networking. To let them know of my existence.
I'm trying to make a multiplayer network game, and I want the clients to be able to see all the games available to choose which one to join.
I want to know how to broadcast from the server and also how to make the clients listen.

Please make it simple, I'm a newbie :)

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴随着你 2024-11-25 19:56:42

要广播数据包,请将它们发送到给定子网的广播地址(子网的最后一个地址)。 IP 255.255.255.255零网络的广播地址。

IP 广播地址 255.255.255.255 存在特殊定义。它是零网络的广播地址或0.0.0.0,在互联网协议标准中代表该网络,即本地网络。根据定义,到此地址的传输受到限制,因为连接本地网络到互联网的路由器永远不会转发该地址。

广播地址

因此,要广播到您当前的网络,请将数据包发送到255.255.255.255< /代码>。

To broadcast data packets, send them to the broadcast address of the given subnet (the last address of the subnet). The IP 255.255.255.255 is the broadcast address for the zero network.

A special definition exists for the IP broadcast address 255.255.255.255. It is the broadcast address of the zero network or 0.0.0.0, which in Internet Protocol standards stands for this network, i.e. the local network. Transmission to this address is limited by definition, in that it is never forwarded by the routers connecting the local network to the Internet.

Broadcast address

So to broadcast to your current network, send the packets to 255.255.255.255.

逆流 2024-11-25 19:56:42

不要混淆术语。

广播通常用于UDP。 UDP 不可靠,因为它不检查客户端是否收到所有数据包。向大量客户端打开大量 TCP 连接不会被广播。

要让您的客户端侦听端口,您需要使用 ServerSocket 并读取它。

Do not confuse terms.

Broadcast is usually used for UDP. UDP is unreliable in the sense that it does not check if all of the packets are received by the clients. Opening a lot of TCP connections to a lot of clients is not broadcast.

To have your clients listen to a port, you need to use ServerSocket and read it.

昨迟人 2024-11-25 19:56:42

我建议您使用 PubSubHubbub 或类似协议。基本上,您将有一个“中心”,您可以将要“广播”的通知发送到该“中心”。每个节点都通过提供一个 URL 来订阅该主题,当新数据到达时,集线器可以调用该 URL。当“集线器”收到此广播时,集线器会联系每个订阅 URL,让节点知道有新数据。

I recommend that you use PubSubHubbub or a similar protocol. Basically, you would have a "hub" to which you send the notification that you want to have "broadcasted". Each of the nodes subscribes to the topic, by providing a URL that the hub can invoke when new data has arrived. When the "hub" receives this broadcast, the hub contacts each subscription URL to let the node know there is new data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文