1 // Tags: not-a-test |
|
2 |
|
3 /* |
|
4 Copyright (C) 1999 Hewlett-Packard Company |
|
5 |
|
6 This file is part of Mauve. |
|
7 |
|
8 Mauve is free software; you can redistribute it and/or modify |
|
9 it under the terms of the GNU General Public License as published by |
|
10 the Free Software Foundation; either version 2, or (at your option) |
|
11 any later version. |
|
12 |
|
13 Mauve is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Mauve; see the file COPYING. If not, write to |
|
20 the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 Boston, MA 02111-1307, USA. |
|
22 */ |
|
23 |
|
24 package gnu.testlet.java.net.MulticastSocket; |
|
25 import gnu.testlet.TestHarness; |
|
26 import java.net.*; |
|
27 |
|
28 |
|
29 class MulticastServer extends Thread { |
|
30 |
|
31 protected static TestHarness harness; |
|
32 |
|
33 private int serverPort; |
|
34 private MulticastSocket socket; |
|
35 private InetAddress address; |
|
36 private DatagramPacket packet; |
|
37 |
|
38 public MulticastServer(int nPort) { |
|
39 try { |
|
40 serverPort = nPort; |
|
41 socket = new MulticastSocket(); |
|
42 address = InetAddress.getByName("230.0.0.1"); |
|
43 } |
|
44 catch (Exception e) { |
|
45 System.out.println("Server constructor"); |
|
46 e.printStackTrace(); |
|
47 } |
|
48 } |
|
49 |
|
50 public void run() { |
|
51 //System.out.println("Starting Server"); |
|
52 |
|
53 |
|
54 try { |
|
55 String[] cmd = new String[5]; |
|
56 |
|
57 cmd[0] = "hello"; |
|
58 cmd[1] = "there"; |
|
59 cmd[2] = "this is"; |
|
60 cmd[3] = "multicast"; |
|
61 cmd[4] = "bye"; |
|
62 |
|
63 for(int i = 0; i < 5; i++){ |
|
64 packet = new DatagramPacket(cmd[i].getBytes(), cmd[i].length(), |
|
65 address, serverPort); |
|
66 // System.out.println("Sent: " + cmd[i]); |
|
67 socket.send(packet); |
|
68 } |
|
69 socket.close(); |
|
70 } |
|
71 catch (Exception e) { |
|
72 System.out.println("Server run failed"); |
|
73 e.printStackTrace(); |
|
74 } |
|
75 } |
|
76 |
|
77 } |
|