package com;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;
import java.util.Random;
public class ServerThread extends Thread {
Socket client=null;
public ServerThread(Socket sclient) {
// TODO 自动生成构造函数存根
this.client=sclient;
}
public void start() {
// TODO 自动生成方法存根
try {
this.run();
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
try {
String str="";
OutputStream out = null;
out = client.getOutputStream();
while (true) {
//System.out.println(this.getName() + "------" + i++);
Date d = new Date();
if(new Random().nextInt()*100 < 50){
str = "< MESSAGE TYPE=/"error/" TEXT=/"Hello, my name is Morgan!/" TIME=/"" + d.toString() + "/"/>";
} else {
str = "";
}
byte[] s= str.getBytes();
out.write(s);
out.write(0);
out.flush();
this.sleep(2000);
}
} catch (Exception ex){
ex.printStackTrace();
}
}
}