001    
002    import java.io.*;
003    import java.net.*;
004    
005    /**
006     * Hello World Server using ChannelFactory.
007     * Generates a "ChannelFactory" on a desired port 
008     * and gets serverside sockets, displays the server status 
009     * and a recieved message.
010     * @author Heinz Kredel.
011     */
012    public class HelloWorldServCFnio {
013    
014        static int port = 40000; // desired serverport do listen
015    
016        public static void main(String[] args) {
017    
018            ChannelFactoryNio cf = null;
019            try {
020                cf = new ChannelFactoryNio( port );
021                //      System.out.println("Server startet on port "+port);
022    
023                while (true) {
024    
025                    //    System.out.println("waiting for connection ... ");
026                        
027                        SocketChannel c = cf.getChannel();
028                        System.out.println("Channel created"); 
029                        
030                        Object o = c.receive();
031                        System.out.println("message 1 " + o); 
032    
033                        o = c.receive();
034                        System.out.println("message 2 " + o); 
035    
036                        c.close();
037    
038                }
039    
040    
041            } catch (IOException e) {
042                System.out.println("IOException "+e);
043            }
044            catch (ClassNotFoundException e) {
045                System.out.println("ClassNotFoundException "+e);
046            }
047    
048            if ( cf != null ) {
049               cf.close();        
050            }
051        }
052    
053    
054    }