66 lines
1.6 KiB
Java
66 lines
1.6 KiB
Java
package mod_ipchat;
|
|
|
|
import java.io.DataInputStream;
|
|
import java.io.IOException;
|
|
import java.net.Socket;
|
|
import java.util.Scanner;
|
|
|
|
public class ChatInThread
|
|
implements Runnable {
|
|
Scanner scn = new Scanner(System.in);
|
|
DataInputStream in;
|
|
boolean kill = false;
|
|
|
|
public ChatInThread(Socket socket) {
|
|
try {
|
|
this.in = new DataInputStream(socket.getInputStream());
|
|
}
|
|
catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
block : do {
|
|
try {
|
|
do {
|
|
String msg = this.in.readUTF();
|
|
if (this.kill) {
|
|
this.in.close();
|
|
break block;
|
|
}
|
|
if (msg.equalsIgnoreCase("xxx")) {
|
|
this.in.close();
|
|
break block;
|
|
}
|
|
System.out.println(msg);
|
|
Thread.sleep(1000);
|
|
} while (true);
|
|
}
|
|
catch (IOException e) {
|
|
e.printStackTrace();
|
|
continue;
|
|
}
|
|
catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
continue;
|
|
}
|
|
|
|
} while (true);
|
|
System.out.println("Chatin Done");
|
|
}
|
|
|
|
public boolean isKill() {
|
|
return this.kill;
|
|
}
|
|
|
|
public void setKill(boolean kill) {
|
|
this.kill = kill;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|