/Users/lyon/j4p/src/net/multicast/ChatRcvr.java

1    package net.multicast; 
2     
3    import gui.JInfoFrame; 
4     
5    import java.io.IOException; 
6    import java.net.InetAddress; 
7     
8    /** 
9     * Copyright DocJava, inc. 
10    * User: lyon 
11    * Date: Oct 27, 2004 
12    * Time: 5:08:08 AM 
13    */ 
14   public class ChatRcvr extends Thread { 
15       private McastUtil mcu; 
16       private JInfoFrame jif; 
17    
18       public ChatRcvr(McastUtil mcu, JInfoFrame jif) { 
19           this.jif = jif; 
20           this.mcu = mcu; 
21           start();                // start calls run 
22       } 
23    
24       public void run() { 
25           try { 
26               while (true) { 
27                   processBytes(); 
28               } 
29           } catch (IOException e) { 
30               e.printStackTrace(); 
31           } 
32       } 
33    
34       private void processBytes() throws IOException { 
35           String tmp; 
36           byte b[] = mcu.getBytes(); 
37           tmp = new String(b, 0, b.length); 
38           InetAddress address = mcu.getInetAddress(); 
39           jif.println(address.getCanonicalHostName()); 
40           jif.println("\n\nRecived: \"" + 
41                   "ip=" + address + 
42                   tmp + 
43                   "\"\nMessage Length is: " + 
44                   tmp.length()); 
45       } 
46   } 
47