package com.github.luohaha.server.test;

import java.io.IOException;

import com.github.luohaha.param.ServerParam;
import com.github.luohaha.server.LightCommServer;

public class TestServer {

	public static void main(String[] args) {
		try {
			ServerParam param = new ServerParam("localhost", 8888);
			param.setBacklog(128);
			param.setOnAccept((conn) -> {
				System.out.println("accept!");
			});
			param.setOnRead((conn, data) -> {
				System.out.println("read!");
			});
			param.setOnWrite((conn) -> {
				try {
					conn.write(String.valueOf(System.currentTimeMillis()).getBytes());
					conn.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			});
			param.setOnClose((conn) -> {
				System.out.println("close!");
				try {
					conn.doClose();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			});
			LightCommServer server = new LightCommServer(param, 4);
			server.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

@@ -61,16 +61,47 @@
 ception;
+%0Aimport java.net.SocketAddress;
 %0A%0Aimport
@@ -373,22 +373,20 @@
 nAccept(
-(
 conn
-)
  -%3E %7B%0A%09%09
@@ -414,24 +414,264 @@
 %22accept!%22);%0A
+%09%09%09%09try %7B%0A%09%09%09%09%09conn.setKeepAlive(false);%0A%09%09%09%09%09SocketAddress address = conn.getRemoteAddress();%0A%09%09%09%09%09System.out.println(address.toString());%0A%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A
 %09%09%09%7D);%0A%09%09%09pa
@@ -762,22 +762,20 @@
 OnWrite(
-(
 conn
-)
  -%3E %7B%0A%09%09
@@ -850,24 +850,70 @@
 etBytes());%0A
+%09%09%09%09%09System.out.println(conn.getKeepAlive());%0A
 %09%09%09%09%09conn.cl
@@ -1050,14 +1050,12 @@
 ose(
-(
 conn
-)
  -%3E 

update test