| MulticastServerTool.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
14
15 package com.liferay.util.transport;
16
17 import java.net.DatagramPacket;
18 import java.net.InetAddress;
19
20 /**
21 * <a href="MulticastServerTool.java.html"><b><i>View Source</i></b></a>
22 *
23 * <p>
24 * A server that will send out heart beat messages until you kill it. This
25 * enables you to try and debug multicast issues.
26 * </p>
27 *
28 * @author Michael C. Han
29 */
30 public class MulticastServerTool {
31
32 public static void main(String[] args) {
33 try {
34 int port = Integer.parseInt(args[1]);
35 long interval = Long.parseLong(args[2]);
36
37 DatagramHandler handler = new DatagramHandler() {
38
39 public void process(DatagramPacket packet) {
40 String s = new String(
41 packet.getData(), 0, packet.getLength());
42
43 System.out.println(s);
44 }
45
46 public void errorReceived(Throwable t) {
47 t.printStackTrace();
48 }
49
50 };
51
52 MulticastTransport transport = new MulticastTransport(
53 handler, args[0], port);
54
55 transport.connect();
56
57 String msg =
58 InetAddress.getLocalHost().getHostName() + ":" + port +
59 " heartbeat " ;
60
61 int i = 0;
62
63 while (true) {
64 transport.sendMessage(msg + i);
65
66 i++;
67
68 Thread.sleep(interval);
69 }
70 }
71 catch (Exception e) {
72 e.printStackTrace();
73
74 System.err.println(
75 "Usage: java MulticastServerTool multicastAddress port " +
76 "interval");
77
78 System.exit(1);
79 }
80 }
81
82 }