Java代碼
package test
import java
import java
import java
import java
import java
import java
import
import
import
public class TalkMe {
public static void main(String[] args) {
System
TalkMe talk = new TalkMe();
talk
try {
talk
} catch (IOException e) {
e
}
}
private Thread listener(){
return new Thread() {
public void run() {
DataInputStream dataIS = null;
String clientSay;
try {
ServerSocket server = new ServerSocket(
Socket socket = server
while (true) {
dataIS = new DataInputStream(socket
clientSay = dataIS
System
}
} catch (IOException e) {
e
}
}
};
}
private Thread talker(final String ip){
return new Thread(){
public void run() {
Socket socket = null;
InputStreamReader stdin=new InputStreamReader(System
BufferedReader br=new BufferedReader(stdin);
DataInputStream dataIS = new DataInputStream(System
OutputStream os;
PrintStream ps;
String say =
boolean flag = true;
while (flag) {
if (flag)
System
try {
socket = new Socket(ip
System
flag = true;
os = socket
ps = new PrintStream(os);
while (true) {
say = dataIS
ps
}
} catch (UnknownHostException e) {
try {
sleep(
} catch (InterruptedException e
e
}
} catch (IOException e) {
}
}
}
};
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26166.html