
import java.io.*;
import java.net.*;

/**
 * Hello World Server using ChannelFactory.
 * Generates a "ChannelFactory" on a desired port 
 * and gets serverside sockets, displays the server status 
 * and a recieved message.
 * @author Heinz Kredel.
 */
public class HelloWorldServCFnio {

    static int port = 40000; // desired serverport do listen

    public static void main(String[] args) {

        ChannelFactoryNio cf = null;
	try {
            cf = new ChannelFactoryNio( port );
	    //	    System.out.println("Server startet on port "+port);

	    while (true) {

         	//    System.out.println("waiting for connection ... ");
		    
                    SocketChannel c = cf.getChannel();
         	    System.out.println("Channel created"); 
		    
                    Object o = c.receive();
         	    System.out.println("message 1 " + o); 

                    o = c.receive();
         	    System.out.println("message 2 " + o); 

                    c.close();

	    }


	} catch (IOException e) {
	    System.out.println("IOException "+e);
	}
	catch (ClassNotFoundException e) {
	    System.out.println("ClassNotFoundException "+e);
	}

        if ( cf != null ) {
           cf.close();        
        }
    }


}
