package me.dslztx.assist.server;

import java.io.InputStream;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TCPSocketServerTest {

    private static final Logger logger = LoggerFactory.getLogger(TCPSocketServer.class);

    @Test
    public void test() {
        try {
            TCPSocketServer tcpSocketServer = new TCPSocketServer("127.0.0.1", 10020);
            tcpSocketServer.start(new HandlerFactoryTest(), null);

        } catch (Exception e) {
            logger.error("", e);
            Assert.fail();
        }
    }
}

class HandlerFactoryTest implements HandlerFactory {

    @Override
    public Handler createHandler(Socket socket) {
        return new HandlerTest(socket);
    }
}

class HandlerTest extends Handler {

    private static final Logger logger = LoggerFactory.getLogger(HandlerTest.class);

    public HandlerTest(Socket socket) {
        super(socket);
    }

    @Override
    void handle(Socket socket) {
        try {
            InputStream in = socket.getInputStream();

            int loop = 20;
            while (true) {
                if (loop == 0)
                    break;

                byte[] bb = new byte[1024];

                int cnt = 0;
                while ((cnt = in.read(bb)) != -1) {
                    System.out.println(new String(bb, 0, cnt));
                }

                loop--;

                TimeUnit.SECONDS.sleep(5);
            }
        } catch (Exception e) {
            logger.error("", e);
        }
    }
}
@@ -55,16 +55,45 @@
 Stream;%0A
+import java.io.OutputStream;%0A
 import j
@@ -108,16 +108,16 @@
 Socket;%0A
-
 import j
@@ -579,24 +579,122 @@
 (), null);%0A%0A
+            Thread.sleep(10000);%0A%0A            multiClients();%0A%0A            Thread.sleep(1000000);%0A
         %7D ca
@@ -784,24 +784,888 @@
      %7D%0A    %7D
+%0A%0A    private void multiClients() %7B%0A        for (int index = 0; index %3C 10; index++) %7B%0A            new Thread(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    try %7B%0A                        Socket socket = new Socket(%22127.0.0.1%22, 10020);%0A                        socket.setSoTimeout(5000);%0A                        OutputStream out = socket.getOutputStream();%0A%0A                        String s = %22hello world%22;%0A%0A                        out.write(s.getBytes());%0A%0A                        out.flush();%0A%0A                        s = %22this is my first socket program%22;%0A                        out.write(s.getBytes());%0A                        out.flush();%0A                    %7D catch (Exception e) %7B%0A                        e.printStackTrace();%0A                    %7D%0A                %7D%0A            %7D).start();%0A        %7D%0A    %7D
 %0A%7D%0A%0Aclass Ha
@@ -2319,16 +2319,16 @@
 nt = 0;%0A
-
         
@@ -2367,24 +2367,82 @@
 )) != -1) %7B%0A
+                    System.out.println(%22test cnt%22 + cnt);%0A
             

update TCPSocketServerTest