package at.floating_integer.sdb.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

public class Server {
	public Server(int port) throws IOException {
		AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open();

		serverSocket.bind(new InetSocketAddress(port));

		serverSocket.accept(null, new CompletionHandler<AsynchronousSocketChannel, Void>() {
			@Override
			public void completed(AsynchronousSocketChannel result, Void attachment) {
				handle(result);
			}

			@Override
			public void failed(Throwable exc, Void attachment) {
				// TODO Auto-generated method stub

			}
		});

	}

	protected void handle(AsynchronousSocketChannel result) {
		result.write(ByteBuffer.wrap("hallo!\n".getBytes()));
	}
}

@@ -283,30 +283,126 @@
 er;%0A
-%0Apublic class Server %7B
+import java.util.logging.Logger;%0A%0Apublic class Server %7B%0A%09private static final Logger L = Logger.getAnonymousLogger();%0A
 %0A%09pu
@@ -910,16 +910,70 @@
 %0A%09%09%7D);%0A%0A
+%09%09L.info(%22Server started listening on port %22 + port);%0A
 %09%7D%0A%0A%09pro
@@ -1027,16 +1027,179 @@
 sult) %7B%0A
+%09%09try %7B%0A%09%09%09L.info(%22client connected: %22 + result.getRemoteAddress());%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %09%09result

add logging