进阶day11-网络编程_TCP文件上传的客户端实现
This commit is contained in:
@@ -30,14 +30,11 @@ public class TcpClientDemo04 {
|
||||
//1.创建客户端对象
|
||||
//Socket(String host, int port) 创建流套接字并将其连接到指定主机上的指定端口号。
|
||||
Socket client = new Socket("192.168.22.51", 10001);
|
||||
|
||||
//2.获取字节输出流,发送请求数据
|
||||
OutputStream os = client.getOutputStream();
|
||||
os.write("淘宝的官网".getBytes());
|
||||
|
||||
//注意:当发送完毕请求数据后,要设置结束的标记,否则服务器会长时间等待客户端的请求数据
|
||||
client.shutdownOutput();
|
||||
|
||||
//3.获取字节输入流,接收响应数据
|
||||
InputStream is = client.getInputStream();
|
||||
//一次读字节数组的方式来读取响应数据
|
||||
|
||||
Reference in New Issue
Block a user