package com.lovecoding.day22.tcp01;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class ServerTCP {
    public static void main(String[] args) throws IOException {
        //创建服务端 端口 0-65535
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("服务器启动");

        //获取请求的socket
        Socket accept = serverSocket.accept();

        //获取输入信息
        InputStream is = accept.getInputStream();
        byte[] bytes = new byte[1024];
        int read = is.read(bytes);
        System.out.println("客户端信息："+new String(bytes,0,read));

        //响应
        PrintStream ps = new PrintStream(accept.getOutputStream());
        ps.println("你好");

        accept.close();
        serverSocket.close();
    }

}
