public void run(){
int i=0;
String s="";
try{
while(true){
s =dis.readUTF();
if (s.endsWith("say $+$getnumber")){
Random random = new Random();
randomNumber = random.nextInt(100);
dos.writeUTF("产生了一个100以内的数");
}
if (!s.endsWith("太大了")&&
!s.endsWith("太小了")&&
!s.endsWith("产生了一个100以内的数")&&
!s.endsWith("不是一个数字")&&
!s.endsWith("say $+$getnumber")){
System.out.println(s);
try{
int a = s.indexOf("say ");
String ss = s.substring(a+4,s.length());
i=Integer.parseInt(ss);
}
catch(NumberFormatException e){
dos.writeUTF("不是一个数字");
}
if (i!=randomNumber){
if(i>randomNumber){
dos.writeUTF(i+"太大了");
}else{
dos.writeUTF(i+"太小了");
}
}else{
dos.writeUTF(i+"对了");
}
}
ta.append("I say: "+s); //accept the msg
ta.append("\n");
}
}
catch(IOException e){
System.out.println("conncttiong error");
}
}
public int getRandomNumber(){
return randomNumber;
}