forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCP_ChatClient.java
More file actions
43 lines (35 loc) · 1.1 KB
/
TCP_ChatClient.java
File metadata and controls
43 lines (35 loc) · 1.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
33
34
35
36
37
38
39
40
41
42
43
package netpck;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
public class TCP_ChatClient {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException, IOException {
// TODO Auto-generated method stub
Socket s = new Socket("localhost",1406);
DataInputStream di = new DataInputStream(s.getInputStream());
DataOutputStream ds = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String sin = "" , sout = "" ;
System.out.println("<< Client side >>");
while (!sin.equalsIgnoreCase("bye") && !sin.equalsIgnoreCase("jsk")) {
System.out.println("Enter Message : ");
sout = br.readLine();
ds.writeUTF(sout);
ds.flush();
sin = di.readUTF();
System.out.println("[CLIENT] Received Message is : "+sin);
}
ds.close();
di.close();
s.close();
}
}