Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
29 lines (28 loc) · 754 Bytes

File metadata and controls

29 lines (28 loc) · 754 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* 范例名称:简单的client/server程序
* 源文件名称:TestClient.java/TestServer.java
* 要 点:
* 1. Java Socket编程步骤
* 2. Socket/ServerSocket类用法
* 3. 通过Socket对象可以获取通信对方Socket的信息
*/
import java.net.*;
import java.io.*;
public class TestServer {
public static void main(String args[]) {
try {
ServerSocket s = new ServerSocket(8888);
while (true) {
Socket s1 = s.accept();
OutputStream os = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
dos.writeUTF("Hello," + s1.getInetAddress() +
"port#" +s1.getPort() + " bye-bye!");
dos.close();
s1.close();
}
}catch (IOException e) {
e.printStackTrace();
System.out.println("程序运行出错:" + e);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.