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
28 lines (26 loc) · 704 Bytes

File metadata and controls

28 lines (26 loc) · 704 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
/* 范例名称:简单的client/server程序
* 源文件名称:TestClient.java/TestServer.java
* 要 点:
* 1. Java Socket编程步骤
* 2. Socket/ServerSocket类用法
* 3. 通过Socket对象可以获取通信对方Socket的信息
*/
import java.net.*;
import java.io.*;
public class TestClient {
public static void main(String args[]) {
try {
Socket s1 = new Socket("127.0.0.1", 8888);
InputStream is = s1.getInputStream();
DataInputStream dis = new DataInputStream(is);
System.out.println(dis.readUTF());
dis.close();
s1.close();
} catch (ConnectException connExc) {
connExc.printStackTrace();
System.err.println("服务器连接失败!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.