-
Notifications
You must be signed in to change notification settings - Fork 0
/
TPimplement.java
40 lines (38 loc) · 1.11 KB
/
TPimplement.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
package com.sachet.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class TPimplement implements Runnable{
private Socket socket;
public TPimplement(Socket socket){
this.socket = socket;
}
public void run(){
try{
BufferedReader input = new BufferedReader(
new InputStreamReader(
socket.getInputStream())
);
PrintWriter output = new PrintWriter(
socket.getOutputStream()
,true
);
String echoString;
while(true){
echoString = input.readLine();
if(echoString.equals("exit")){
break;
}
System.out.println(socket.getPort()+":"
+echoString);
output.println(echoString);
}
}catch(IOException e){
try{
socket.close();
}catch(IOException e1){}
}
}
}