-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths1.java
More file actions
62 lines (62 loc) · 1.13 KB
/
Copy paths1.java
File metadata and controls
62 lines (62 loc) · 1.13 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
61
62
package socketp1;
import java.io.*;
import java.net.*;
public class s1
{
public static void main(String args[]) throws IOException
{
ServerSocket ss=new ServerSocket(4999);
while(true)
{
Socket s = null;
try
{
s=ss.accept();
DataInputStream in=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
Thread t=new ClientHandler(s,in,out);
t.start();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
static class ClientHandler extends Thread
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
Socket s;
DataInputStream in;
DataOutputStream out;
public ClientHandler(Socket so,DataInputStream din,DataOutputStream dout)
{
s=so;
in=din;
out=dout;
}
public void run()
{
try
{
while(true)
{
String re=in.readUTF();
System.out.println("client:"+re);
if(re.equalsIgnoreCase("bye"))
{
s.close();
break;
}
System.out.print("->");
String se=bf.readLine();
out.writeUTF(se);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}