1 87 package org.codehaus.loom.demos.distributed.block; 88 89 import java.io.IOException ; 90 import java.io.ObjectInputStream ; 91 import java.net.ServerSocket ; 92 import java.net.Socket ; 93 94 import org.codehaus.loom.demos.distributed.api.Server; 95 96 99 public class ServerImpl 100 implements Server 101 { 102 public void processSocket( final Socket socket ) 103 { 104 try 105 { 106 final ObjectInputStream ois = 107 new ObjectInputStream ( socket.getInputStream() ); 108 109 String string = null; 110 111 try 112 { 113 string = (String )ois.readObject(); 114 } 115 catch( final ClassNotFoundException cnfe ) 116 { 117 } 118 119 message( string ); 120 ois.close(); 121 socket.close(); 122 } 123 catch( final IOException ioe ) 124 { 125 System.out.println( "Unexpected IO Exception" ); 126 } 127 } 128 129 public void message( String string ) 130 { 131 System.out.println( "Message string passed = " + string ); 132 } 133 134 public static void main( final String [] args ) 135 throws IOException 136 { 137 final ServerImpl svr = new ServerImpl(); 138 final ServerSocket serverSocket = new ServerSocket ( 7654 ); 139 140 System.out.println( "Server listening on port " + 7654 ); 141 System.out.println( "Ctrl-C to exit" ); 142 143 while( true ) 144 { 145 svr.processSocket( serverSocket.accept() ); 146 } 147 } 148 } 149 | Popular Tags |