Created
March 4, 2012 17:24
-
-
Save casidiablo/1973987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.DatagramPacket; | |
import java.net.InetAddress; | |
import java.net.MulticastSocket; | |
/** | |
* @author cristian | |
*/ | |
public class MultiServer { | |
public static void main(String[] args) throws IOException { | |
byte[] buf = new byte[256]; | |
DatagramPacket packet = new DatagramPacket(buf, buf.length); | |
MulticastSocket socket = new MulticastSocket(4445); | |
// las direcciones multicast rango: 224.0.0.1 a 239.255.255.255 | |
socket.joinGroup(InetAddress.getByName("239.255.255.255")); | |
socket.receive(packet); | |
String recibido = new String(packet.getData()); | |
System.out.println("llego paquete: " + recibido); | |
InetAddress address = packet.getAddress(); | |
int port = packet.getPort(); | |
packet = new DatagramPacket(buf, buf.length, address, port); | |
socket.send(packet); | |
socket.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment