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