package com.lovecoding.day22.tcp01;

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

//客户端
public class ClentTCP {

    public static void main(String[] args) throws IOException {
        //192.168.18.13
        Socket socket = new Socket("192.168.18.31",8888);
        //发送数据
        OutputStream os = socket.getOutputStream();
        //hello
        byte[] bytes = "hello".getBytes();
        os.write(bytes);
        System.out.println("发送信息成功");
        //接收
        InputStream is = socket.getInputStream();
        byte[] bytes1 = new byte[1024];
        int len = is.read(bytes1);
        String s = new String(bytes1, 0, len);
        System.out.println("响应信息："+s);
        //关闭
        socket.close();
    }

}
