001
014
015 package com.liferay.util.transport;
016
017 import java.net.DatagramPacket;
018 import java.net.InetAddress;
019
020
028 public class MulticastServerTool {
029
030 public static void main(String[] args) {
031 try {
032 int port = Integer.parseInt(args[1]);
033 long interval = Long.parseLong(args[2]);
034
035 DatagramHandler handler = new DatagramHandler() {
036
037 public void process(DatagramPacket packet) {
038 String s = new String(
039 packet.getData(), 0, packet.getLength());
040
041 System.out.println(s);
042 }
043
044 public void errorReceived(Throwable t) {
045 t.printStackTrace();
046 }
047
048 };
049
050 MulticastTransport transport = new MulticastTransport(
051 handler, args[0], port);
052
053 transport.connect();
054
055 String msg =
056 InetAddress.getLocalHost().getHostName() + ":" + port +
057 " heartbeat " ;
058
059 int i = 0;
060
061 while (true) {
062 transport.sendMessage(msg + i);
063
064 i++;
065
066 Thread.sleep(interval);
067 }
068 }
069 catch (Exception e) {
070 e.printStackTrace();
071
072 System.err.println(
073 "Usage: java MulticastServerTool multicastAddress port " +
074 "interval");
075
076 System.exit(1);
077 }
078 }
079
080 }