/*
* 这个代码说明的是客户端使用半关闭方法
* */
package comOne;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class BanGuanBi {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Socket socket = new Socket("210.41.160.7", 13);
Scanner in = new Scanner(socket.getInputStream());
PrintWriter writer = new PrintWriter(socket.getOutputStream());
//发送请求数据
writer.println("正在发送请求的数据!!");
writer.flush();
socket.shutdownOutput();
//现在socket是半关闭的状态
//读取请求数据
while(in.hasNextLine()){
String line = in.nextLine();
}
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
时间: 2024-11-10 10:03:34