Created
January 5, 2014 16:29
-
-
Save VuokkoVuorinnen/8270317 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
package testapps; | |
import java.io.IOException; | |
import java.net.DatagramPacket; | |
import java.net.InetAddress; | |
import java.net.MulticastSocket; | |
public class DateClient { | |
private static MulticastSocket multicastSocket; | |
private static InetAddress group; | |
private static byte[] buffer = new byte[256]; | |
public static void main(String[] args) { | |
try { | |
group = InetAddress.getByName("230.0.0.1"); | |
multicastSocket = new MulticastSocket(4446); | |
multicastSocket.joinGroup(group); | |
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, 4446); | |
for (int i = 0; i < 10; ++i) { | |
multicastSocket.receive(packet); | |
System.out.println(new String(packet.getData())); | |
} | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} finally { | |
try { | |
multicastSocket.leaveGroup(group); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} finally { | |
multicastSocket.close(); | |
System.out.println("Disconnected"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment