-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
31 lines (30 loc) · 963 Bytes
/
Server.java
File metadata and controls
31 lines (30 loc) · 963 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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String args[]){
ServerSocket server = null;
Socket you = null;
String s = null;
DataOutputStream out = null;
DataInputStream in = null;
try{
server = new ServerSocket(4441);
}catch (IOException e){
System.out.println("ERROR:" + e);
}
try{
you = server.accept();
in = new DataInputStream(you.getInputStream());
out = new DataOutputStream(you.getOutputStream());
while (true){
s = in.readUTF();
if(s != null) break;
}
out.writeUTF("客户,你好,我是服务器!");
out.close();
}catch (IOException e){}
}
}