package com.huimv.datacollection.tcp.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9977);

        Socket accept = serverSocket.accept();

        InputStream is = accept.getInputStream();

        int len;
        byte[] bytes = new byte[1024*8];

        while ((len = is.read(bytes))!= -1) {
            System.out.println(new String(bytes,0,len));
        }

        OutputStream os = accept.getOutputStream();
        os.write("你谁啊?".getBytes());
        accept.shutdownOutput();

        is.close();
        os.close();
        accept.close();
        serverSocket.close();



    }
}