?? clinet.java~1~
字號(hào):
package one_piece;// 程序:客戶端線程類// 范例文件:clientskt.javaimport java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;class Clinet extends Thread{ Socket skt; InetAddress host; int port; BufferedReader theInputStream; PrintStream theOutputStream; String readin; CHUANGTI chat; public Clinet(CHUANGTI chat) //public Clinet(String ip, int p, CHUANGTI chat) { try { //host = InetAddress.getByName(ip); //port = p; host = InetAddress.getByName("127.0.0.1"); port = 6000; this.chat = chat; } catch (IOException e) { chat.jTextArea1.append(e.toString()); } } public void run() { try { chat.jTextArea1.append("嘗試連線......"); skt = new Socket(host, port); chat.jTextArea1.append("連線成功\n"); theInputStream = new BufferedReader( new InputStreamReader(skt.getInputStream())); theOutputStream = new PrintStream(skt.getOutputStream()); while(true) { readin = theInputStream.readLine(); chat.jTextArea1.append(readin + "\n"); } } catch (SocketException e) { chat.jTextArea1.append("連線中斷!\n"); try { skt.close(); } catch (IOException err) { chat.jTextArea1.append(err.toString()); } } catch (IOException e) { chat.jTextArea1.append(e.toString()); } } public void dataout(String data) { theOutputStream.println(data); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -