java - DatagramSocket Broadcast Behavior (Windows vs. Linux) -


backstory:
have wireless device creates it's own ssid, assigns ip address using auto-ip, , begins broadcasting discovery information 255.255.255.255. (unfortunately, not easily support multicast)

what i'm trying do:
need able receive discovery information, send configuration information device. problem is, auto-ip, "ip negotiation" process can take minutes on windows, etc (during time can see broadcasts , can send broadcast information device).

so enumerate connected network interfaces (can't directly tell used talk device), create datagramsocket each of addresses, start listening. if receive discovery information via particular socket, know can use same socket send data device. this works on windows.

the problem:
on linux , osx, following code not receive broadcast packets:

byte[] addr = {(byte)169, (byte)254, (byte)6, (byte)215};   datagramsocket foo = new datagramsocket(new inetsocketaddress(inetaddress.getbyaddress(addr), port_num));   while (true)   {   byte[] buf = new byte[256];   datagrampacket pct = new datagrampacket(buf, buf.length);   foo.receive(pct);   system.out.println( iobuffer.wrap(buf).gethexdump() );   } 

in order receive broadcast packets (on linux/osx), need create datagramsocket using:
datagramsocket foo = new datagramsocket(port_num);

however, when use socket send data device, packet routed os (i'm assuming) , since interface of interest may in middle of auto-ip negotiation, fails.

thoughts on following?

  • how "working" windows behavior happen on linux/osx
  • a better way handle process

thanks in advance!

i not think problem code. have checked if osx/linux has correctly allowed address / port number through firewalls? had simple problem in past =p..

fyi, there nice technology called zero-configuration built solve problem. easy learn recommend having @ well.

good luck.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -