-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.java
54 lines (43 loc) · 1.58 KB
/
client.java
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
44
45
46
47
48
49
50
51
52
53
54
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
public class client {
private static DataInputStream in;
private static DataOutputStream out;
private static final String ip="localhost";
private static final int port=5080;
public static void main(String []args)throws IOException{
Socket socket=new Socket(ip,port);
Scanner sc=new Scanner(System.in);
System.out.println("Enter the data to be sent in format of message # client's name");
in=new DataInputStream(new BufferedInputStream(socket.getInputStream()));
out=new DataOutputStream(socket.getOutputStream());
Thread readMessage=new Thread(new Runnable(){
public void run(){
while(true){
try {
String message=in.readUTF();
System.out.println(message);
} catch (Exception e) {
}
}
}
});
Thread sendMessage=new Thread(new Runnable(){
public void run(){
while(true){
try {
String userdata=sc.nextLine();
out.writeUTF(userdata);
} catch (Exception e) {
}
}
}
});
readMessage.start();
sendMessage.start();
}
}