forked from eugenejade/JavaTPCProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject06A_Server.java
More file actions
32 lines (31 loc) · 1 KB
/
Project06A_Server.java
File metadata and controls
32 lines (31 loc) · 1 KB
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
import java.net.*;
import java.io.*;
public class Project06A_Server {
public static void main(String[] args) {
ServerSocket ss=null;
try {
ss=new ServerSocket(9999);
System.out.println("Server ready....");
} catch (Exception e) {
e.printStackTrace();
}
while(true) {
try {
Socket socket=ss.accept();
System.out.println("client connect success!");
InputStream in=socket.getInputStream();
DataInputStream dis=new DataInputStream(in);
String message=dis.readUTF();
OutputStream out=socket.getOutputStream();
DataOutputStream dos=new DataOutputStream(out);
dos.writeUTF("[ECHO]"+message+"(from Server!)");
dos.close();
dis.close();
socket.close();
System.out.println("client socket close....");
} catch (Exception e) {
e.printStackTrace();
}
}//while
}//main
}//class