package com.huimv.video;

import org.junit.jupiter.api.Test;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

class VideoApplicationTests {


    /*public static void main(String[] args) {
        //new Thread(new DD()).start();
        while (true){
            ServerSocket serverSocket=null;
            Socket socket=null;
            String msg="hello client,I am server..";
            try {
                //构造ServerSocket实例，指定端口监听客户端的连接请求
                serverSocket=new ServerSocket(10088);
                //建立跟客户端的连接
                socket=serverSocket.accept();


                //向客户端发送消息
                OutputStream os=socket.getOutputStream();
                os.write(msg.getBytes());
                InputStream is=socket.getInputStream();

                //接受客户端的响应
                byte[] b=new byte[1024];
                is.read(b);
                System.out.println(new String(b));

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                //操作结束，关闭socket
                try {
                    serverSocket.close();
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }*/

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10087);

        Socket accept = ss.accept();

        InputStream is = accept.getInputStream();
        int b;
        while((b = is.read())!=-1){
            System.out.println((char) b);
        }

        System.out.println("看看我执行了吗?");
        OutputStream os = accept.getOutputStream();
        os.write("你谁啊?".getBytes());
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你谁啊?");
        bw.newLine();
        bw.flush();

        bw.close();
        is.close();
        accept.close();
        ss.close();
    }


}
