黑马程序员技术交流社区
标题:
【石家庄校区】格式固定逻辑性挺牛
[打印本页]
作者:
飛鸟瞰
时间:
2019-5-13 14:51
标题:
【石家庄校区】格式固定逻辑性挺牛
package
itheima06;
import
java.io.*;
import
java.net.Socket;
/*客户端:数据来自键盘录入,知道发送的数据是886,发送数据结束*/
public class
ClientDemo {
public static void
main(String[] args)
throws
IOException {
Socket s =
new
Socket(
"127.0.0.1"
,
10000
);
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(System.
in
));
BufferedWriter bw =
new
BufferedWriter(
new
OutputStreamWriter(s.getOutputStream()));
String line;
while
((line = br.readLine()) !=
null
) {
if
(
"886"
.equals(line)) {
break
;
}
bw.write(line);
bw.newLine();
bw.flush();
}
s.close();
}
}
=============================================
package
itheima06;
import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.net.ServerSocket;
import
java.net.Socket;
public class
ServerDemo {
public static void
main(String[] args)
throws
IOException {
ServerSocket ss =
new
ServerSocket(
10000
);
Socket s = ss.accept();
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(s.getInputStream()));
String line;
while
((line = br.readLine()) !=
null
) {
System.
out
.println(line);
}
ss.close();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2