开发者

Connecting to broadcast IP address

I am currently working on simple java program that should be able to seek out computer in a local network that runs my second java application, all using UDP networking. One of those apps opens DatagramSocket and starts a thread that processes all of the inputs. The other applicat开发者_运维问答ion connects to broadcast address of current LAN network (e.g. 192.16.0.255), sends a packet and receives the response. I'm not very familiar with the way this works but here is what I'm wondering:

If I launch two of those responding applications each on different computer of the same network and run client application on other computer, which of those will it connect to? I thought it would connect and send packet to both but it connected just to one of them and sometimes not the same one.

Could you please explain this matter to me? I would appreciate it.


If I launch two of those responding applications each on different computer of the same network and run client application on other computer, which of those will it connect to?

Neither, UDP is a connectionless protocol.

I thought it would connect and send packet to both but it connected just to one of them and sometimes not the same one.

UDP is a lossy protocol, sometimes the data will go to both, one or neither. Your router could be setup to try to direct the broadcast traffic, but usually it will attempt to send all packets to all listeners.

BTW: All the listeners must be on the 192.168.0.255 C class subnet. A host with an IP address of 192.168.1.1 may not see this packet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜