package cn.itcast_TCP;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class ClientDemo {
public static void main(String[] args) throws IOException {
// 创建一个套接字对象
Socket s = new Socket("192.168.1.100", 10086);
// 从套接字上获取输出流
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
s.getOutputStream()));
// 封装输入流数据
System.out.println("请输入要发送的能容");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 输出流写入数据
String line = null;
while ((line = br.readLine()) != null) {
if ("886".equals(line)) {
break;
}
bw.write(line);
bw.newLine();
bw.flush();
}
s.close();
}
} |
|