listeningthread.java
来自「一个基于eclipse插件开发的聊天程序」· Java 代码 · 共 49 行
JAVA
49 行
package talkServer.business;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import org.eclipse.swt.widgets.Text;
public class ListeningThread extends Thread {
// SET FOR REFERENCE, REFRESH THE DISPLAY
// Text text;
public ServerSocket server_sock;
int port = 1860;
public ListeningThread(Text text) {
super();
// this.text = text;
}
public void run() {
super.run();
try {
server_sock = new ServerSocket(port); // Server socket.
} catch (IOException e1) {
e1.printStackTrace();
}
while (true) {
Socket accepted_sock = null;
try {
accepted_sock = server_sock.accept();
} catch (IOException e2) {
e2.printStackTrace();
}
// For each socket connection,create a thread to handle it.
new ClientHandlerThread(accepted_sock/*, this.text*/).start();
}
}
public void destroy() {
super.destroy();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?