package Ltian;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class L3 implements Runnable{
private InputStream is;
@Override
public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while(true) {
String mess;
try {
mess = br.readLine();
System.out.println(mess + "\r\n");
} catch (IOException e) {
System.out.println("再见啊妹妹");
break;
}
}
}
public L3(InputStream is) {
super();
this.is = is;
}
public L3() {
super();
}
public InputStream getIs() {
return is;
}
public void setIs(InputStream is) {
this.is = is;
}
}
四//接收消息
package Ltian;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class L4 implements Runnable{
private String from;
private OutputStream os;
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public OutputStream getOs() {
return os;
}
public void setOs(OutputStream os) {
this.os = os;
}
@Override
public void run() {
PrintWriter out = new PrintWriter(os);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while(true){
Scanner sc = new Scanner(System.in);
String msg = from + ":"+sc.nextLine()+"["+sdf.format(new Date())+"]\r\n";
out.print(msg);
out.flush();
}
}
public L4(String from, OutputStream os) {
super();
this.from = from;
this.os = os;
}
public L4() {
super();
}
}