-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
47 lines (44 loc) · 1.45 KB
/
Client.java
File metadata and controls
47 lines (44 loc) · 1.45 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
44
45
46
47
import java.net.*;
import java.io.*;
public class Client {
public static void main(String args[]) throws UnknownHostException, IOException{
Socket s = new Socket("localhost", 7);
PrintWriter out = new PrintWriter(s.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader (s.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
Thread sendMessage = new Thread (new Runnable()
{
@Override
public void run()
{
while (true)
{
try{
String message = stdIn.readLine();
out.println(message);
if (message.equals("exit"))
break;
} catch (IOException e){}
}
}
});
Thread readMessage = new Thread (new Runnable()
{
@Override
public void run()
{
while (true)
{
try{
String input = in.readLine();
System.out.println(input);
if (input.equals("exit"))
break;
} catch (IOException e){}
}
}
});
sendMessage.start();
readMessage.start();
}
}