-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPServer.java
More file actions
32 lines (27 loc) · 770 Bytes
/
TCPServer.java
File metadata and controls
32 lines (27 loc) · 770 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
import java.net.*;
import java.io.*;
import java.util.*;
public class TCPServer {
public static void main(String[] args) throws Exception {
ServerSocket svs = new ServerSocket(5000);
Socket sok = svs.accept();
DataInputStream rfconsole = new DataInputStream(System.in);
DataInputStream rfclient = new DataInputStream(sok.getInputStream());
PrintStream otclient = new PrintStream(sok.getOutputStream());
PrintStream otconsole = new PrintStream(System.out);
while(true){
String s = rfclient.readLine();
otconsole.println("Client: " + s);
if(s.equals("exit")){
break;
}
otconsole.print("Server: ");
String s1 = rfconsole.readLine();
otclient.println(s1);
if(s1.equals("exit")){
break;
}
}
sok.close();
}
}