-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClient.java
More file actions
53 lines (51 loc) · 1.42 KB
/
Copy pathClient.java
File metadata and controls
53 lines (51 loc) · 1.42 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
import java.util.*;
import java.io.*;
import java.net.*;
class Reader implements Runnable
{
DataInputStream dis=null;
Thread t=null;
public Reader(DataInputStream dis)
{
this.dis=dis;
t=new Thread(this);
t.start();
}
public void run()
{
while(!Client.suspend)
{
try{
System.out.println(dis.readUTF());
}
catch(IOException io){System.out.println(io);}
}
}
}
public class Client
{
static DataInputStream dis=null;
static DataOutputStream dos=null;
static Socket socket=null;
static boolean suspend=false;
public static void main(String[] args) throws IOException{
socket=new Socket("192.168.43.221",5000);
System.out.println("Connected Successfully...");
dis=new DataInputStream(socket.getInputStream()); //DataIpStream(InputStream)
dos=new DataOutputStream(socket.getOutputStream());
Reader r=new Reader(dis);
Scanner s=new Scanner(System.in);
String msg="";
while(!msg.equals("exit"))
{
msg=s.nextLine();
if(msg.equals("exit")) suspend=true;
dos.writeUTF(msg);
}
s.close();
try{r.t.join();}catch(InterruptedException ie){}
socket.close();
dos.close();
dis.close();
}
}