I wonder how I can detect LAN servers.
I made a client/server app and it all works fine but you have to manually enter the IP address of the server.
Currently I'm trying to use a DatagramSocket
on the client/server.
The server will send a packet containing its IP address so the client can connect to that address. The packet is send it to its local broadcast IP (192.168.1.255) port 4444.
The client will listen to port 4444. Then receive the packet.
This works if I'm on the same computer (so the is nothing wrong with my code), but not when I try it on another computer and try to connect to my computer.
I'm not that familiar with networking so I was hoping someone can explain to me how to do this properly.
Also, in AIR broadcasting on 255.255.255.255 is not supported: Note: Sending data to a broadcast address is not supported.
source
While you can use 192.168.0.255 on Windows Systems you will get an exception on MacOS X. Instead, you can use Class D IP Broadcast on MacOS X ... 224.0.0.1
In order to achieve this I've created my own solution (which isn't perfect, but the only working way I could think of).
On the server side I create a new DatagramSocket that will send a message to each Ip adress in a certain range.
Then on the client side, add another DatagramSocket. Then bind it to the same port used by the server and set it to receive mode.
Here is my network utils class for those that want to implement this:
To discover other computers in your LAN your server must send UDP broadcasts, which AIR does not support. If your server must be implemented in AIR, you can use a native extension (android/ios) or call a system process via NativeProcess (desktop) that performs the UDP broadcast.
Here are some links that might be useful:
http://lucamezzalira.com/2011/07/29/multicast-udp-socket-in-adobe-air-with-python/
https://github.com/wouterverweirder/AIR-Mobile-UDP-Extension