Biblioteca Java - Blame information for rev 3
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * MulticastServer.java | ||
3 | */ | ||
4 | package lab.scd.net.broadcast; | ||
5 | |||
6 | |||
7 | import java.net.*; | ||
8 | |||
9 | /** | ||
10 | * Class created by @author Mihai HULEA at Feb 26, 2005. | ||
11 | * | ||
12 | * This class is part of the laborator2_net project. | ||
13 | * | ||
14 | */ | ||
15 | public class MulticastServer extends Thread { | ||
16 | |||
17 | DatagramSocket socket; | ||
18 | boolean alive=true; | ||
19 | |||
20 | public MulticastServer() throws SocketException{ | ||
21 | socket = new DatagramSocket(1977); | ||
22 | } | ||
23 | |||
24 | public void run(){ | ||
25 | |||
26 | try{ | ||
27 | System.out.println("Multicast server started."); | ||
28 | while(alive){ | ||
29 | byte[] buf = new byte[256]; | ||
30 | |||
31 | // receive request | ||
32 | DatagramPacket rcvdPacket = new DatagramPacket(buf, buf.length); | ||
33 | |||
34 | //serverul asteapta primire de pachete | ||
35 | socket.receive(rcvdPacket); | ||
36 | /* | ||
37 | String received = new String(packet.getData()); | ||
38 | System.out.println("server received: " + received); | ||
39 | */ | ||
40 | |||
41 | //adresa multicast catre care for fi trimise mesajele | ||
42 | InetAddress group = InetAddress.getByName("230.0.0.1"); | ||
43 | |||
44 | //construieste pachetul | ||
45 | DatagramPacket packet = new DatagramPacket(buf, buf.length, | ||
46 | group, 4446); | ||
47 | |||
48 | packet.setData(rcvdPacket.getData()); | ||
49 | |||
50 | //trimte datele catre adresa multicast | ||
51 | socket.send(packet); | ||
52 | |||
53 | } | ||
54 | |||
55 | }catch(Exception e){ | ||
56 | System.err.println("Server error: "+e.getMessage()); | ||
57 | e.printStackTrace(); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | public static void main(String[] args)throws Exception { | ||
62 | MulticastServer ms = new MulticastServer(); | ||
63 | ms.start(); | ||
64 | /* | ||
65 | MulticastClient mc = new MulticastClient(); | ||
66 | mc.start(); | ||
67 | |||
68 | String msg=""; | ||
69 | while(!msg.equals("exit")){ | ||
70 | BufferedReader sb = new BufferedReader(new InputStreamReader(System.in)); | ||
71 | System.out.print("snd:"); | ||
72 | msg = sb.readLine(); | ||
73 | try{ | ||
74 | mc.sendMessage(msg,"127.0.0.1"); | ||
75 | }catch(Exception e){ | ||
76 | System.err.println("Error sending message:"+e.getMessage()); | ||
77 | } | ||
78 | }//.while | ||
79 | */ | ||
80 | //System.exit(0); | ||
81 | |||
82 | } | ||
83 | } |