-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTcpTest.java
More file actions
37 lines (28 loc) · 873 Bytes
/
Copy pathTcpTest.java
File metadata and controls
37 lines (28 loc) · 873 Bytes
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
30
31
32
33
34
35
36
37
/**
*
*/
package com.test.servlet;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* @author aubrey
* @date 上午10:46:59
*
*/
public class TcpTest {
public static void main(String[] args) throws IOException {
// new Socket(host, port);
ServerSocket server = new ServerSocket(8001);
System.out.println("初始化socketserver完成,等待连接......");
Socket socket = server.accept();
DataInputStream dataIn = new DataInputStream(socket.getInputStream());
System.out.println(dataIn.readUTF());
System.out.println("数据接收完毕......");
DataOutputStream dataOut = new DataOutputStream(socket.getOutputStream());
dataOut.writeUTF("谢谢连接.......");
socket.close();
}
}