KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > phoenixdemo > server > PDKDemoServerImpl


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package phoenixdemo.server;
9
10 import java.io.IOException JavaDoc;
11 import java.io.ObjectInputStream JavaDoc;
12 import java.net.ServerSocket JavaDoc;
13 import java.net.Socket JavaDoc;
14 import phoenixdemo.api.PDKDemoServer;
15
16 /**
17  * @author Paul Hammant <a HREF="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
18  * @version $Revision: 1.5 $
19  */

20 public class PDKDemoServerImpl
21     implements PDKDemoServer
22 {
23     public void processSocket( final Socket JavaDoc socket )
24     {
25         try
26         {
27             final ObjectInputStream JavaDoc ois =
28                 new ObjectInputStream JavaDoc( socket.getInputStream() );
29
30             String JavaDoc string = null;
31
32             try
33             {
34                 string = (String JavaDoc)ois.readObject();
35             }
36             catch( final ClassNotFoundException JavaDoc cnfe )
37             {
38             }
39
40             message(string);
41             ois.close();
42             socket.close();
43         }
44         catch( final IOException JavaDoc ioe )
45         {
46             System.out.println( "Unexpected IO Exception" );
47         }
48     }
49
50     public void message(String JavaDoc string)
51     {
52         System.out.println( "String passed = " + string );
53     }
54
55
56     public static void main( final String JavaDoc[] args )
57         throws IOException JavaDoc
58     {
59         final PDKDemoServerImpl svr = new PDKDemoServerImpl();
60         final ServerSocket JavaDoc serverSocket = new ServerSocket JavaDoc( 7654 );
61
62         System.out.println( "PDK Demo listening on port " + 7654 );
63         System.out.println( "Ctrl-C to exit" );
64
65         while( true )
66         {
67             svr.processSocket( serverSocket.accept() );
68         }
69     }
70 }
71
Popular Tags