-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiThreadServer.java
48 lines (39 loc) · 1.06 KB
/
MultiThreadServer.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
package multithreadserver;
import java.net.*;
import java.io.*;
public class MultiThreadServer implements Runnable
{
Socket client;
public MultiThreadServer(Socket stk)
{
client=stk;
}
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(2000);
Socket stk;
do
{
stk=ss.accept();
System.out.println("Client Connected");
MultiThreadServer mt=new MultiThreadServer(stk);
Thread t=new Thread(mt);
t.start();
}while(true);
}
public void run()
{
try{
StringBuffer buff;
BufferedReader br=new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintStream ps=new PrintStream(client.getOutputStream());
String str;
do
{
str=br.readLine();
buff=new StringBuffer(str);
ps.println(buff.reverse());
}while(!str.equals("bye"));
}catch(Exception e){}
}
}