1 8 package phoenixdemo.block; 9 10 import java.io.IOException ; 11 import java.net.ServerSocket ; 12 import java.net.Socket ; 13 import phoenixdemo.server.PDKDemoServerImpl; 14 15 22 public class SocketThread 23 extends Thread ![JavaDoc](../../../cmn/javadoc.gif) 24 { 25 private PDKDemoServerImpl m_pdkDemoServerImpl; 26 private ServerSocket m_serverSocket; 27 28 protected SocketThread( final PDKDemoServerImpl pdkDemoServerImpl, 29 final int port ) 30 { 31 32 m_pdkDemoServerImpl = pdkDemoServerImpl; 33 34 try 35 { 36 m_serverSocket = new ServerSocket ( port ); 37 } 38 catch( final IOException ioe ) 39 { 40 final String message = "Unable to open listening port. " + 41 "It is probably already being listened to."; 42 throw new RuntimeException ( message ); 43 } 44 } 45 46 51 public void run() 52 { 53 54 while( true ) 55 { 56 try 57 { 58 ConnectionThread ct = new ConnectionThread( m_serverSocket.accept() ); 59 60 ct.start(); 61 } 62 catch( IOException ioe ) 63 { 64 System.out.println( "Some problem with getting a socket for the connetion." ); 65 } 66 } 67 } 68 69 75 class ConnectionThread extends Thread ![JavaDoc](../../../cmn/javadoc.gif) 76 { 77 private Socket m_socket; 78 79 private ConnectionThread( final Socket socket ) 80 { 81 m_socket = socket; 82 } 83 84 public void run() 85 { 86 m_pdkDemoServerImpl.processSocket( m_socket ); 87 } 88 } 89 } 90 | Popular Tags |