Tcp学习Client

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

public class Clinet {
public static void main(String[] args) {



OutputStream out = null;
Socket so = null;


//连接
try {
InetAddress inetAddress = InetAddress.getByName("127.0.0.1");


//端口
int port = 8888;

//建立一个socket连接
so = new Socket(inetAddress,port);

//发送io

out = so.getOutputStream();


out.write("你好我是高刚".getBytes());


} catch (Exception e) {
e.printStackTrace();
}finally {


if (out!=null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}

}


if (so!=null){
try {
so.close();
} catch (IOException e) {
e.printStackTrace();
}
}


}


}
}
posted @ 2022-04-05 19:48  powermain  阅读(35)  评论(0)    收藏  举报