-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
60 lines (58 loc) · 2.09 KB
/
Client.java
File metadata and controls
60 lines (58 loc) · 2.09 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
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.io.*;
import java.net.*;
public class Client implements Runnable
{
static Socket socket=null;
static PrintStream output;
static BufferedReader input=null;
static BufferedReader userip=null;
static boolean flag=false;
public static void main(String[] args)
{
int port=1234;
String host="localhost";
try
{
socket=new Socket(host,port);
userip=new BufferedReader(new InputStreamReader(System.in));
output=new PrintStream(socket.getOutputStream());
input=new BufferedReader(new InputStreamReader(socket.getInputStream()));
}
catch(Exception e)
{
System.err.println("Unknown host"+host);
}
if(socket!=null)
{
try
{
new Thread(new Client()).start();
while(!flag)
{
output.println(userip.readLine());
}
output.close();
input.close();
socket.close();
}
catch(Exception e1)
{
System.err.println("IOException"+e1);
}
}
}
public void run()
{
String msg;
try
{
while((msg=input.readLine())!=null)
System.out.println(msg);
flag=true;
}
catch(IOException e)
{
System.err.println("IOException" + e);
}
}
}