} }
class ServerThread extends Thread { ServerSocket skt; Socket Client; TextArea in; int port,i;
BufferedReader theInputStream; PrintStream theOutputStream; String readin; Face chat; //服务端子线程
public ServerThread(Socket s, Face chat, int i) { this.i = ++i; Client = s;
this.chat = chat; }
public int getI() { return this.i; }
public Socket getClient() { return this.Client; }
public void run() { try {
theInputStream = new BufferedReader(new InputStreamReader(Client .getInputStream()));
theOutputStream = new PrintStream(Client.getOutputStream()); while (true) {
readin = theInputStream.readLine(); chat.ta.append(readin + "\n"); }
} catch (SocketException e) {
chat.ta.append("连线中断!\n"); // 设置组件可用性 chat.clientBtn.setEnabled(true); chat.serverBtn.setEnabled(true); chat.tfaddress.setEnabled(true); chat.tfport.setEnabled(true); try { i - -;
skt.close(); Client.close();
} catch (IOException err) {
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库Socket和多线程编程的聊天程序实现(4)在线全文阅读。
相关推荐: