package cn.iocoder.yudao.module.system.util.socket;


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

//客服端
public class TCPClient {
    public static void main(String[] args) throws IOException {
        //发送100个客户端请求
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        //和服务器创建连接
                        Socket socket = new Socket();
                        socket.connect(new InetSocketAddress("10.10.100.17", 9000), 1000);

                        OutputStream os = socket.getOutputStream();
                        String str="你好服务器====:___:";
                        os.write(str.getBytes());
                        //服务器返回的信息
                        InputStream is=socket.getInputStream();
                        byte[] bytes=new byte[1024];
                        int len=is.read(bytes);
                        System.out.println(new String(bytes,0,len));

                        socket.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }





    }

}


