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