📄 clientskt.java
字号:
/* * clientskt.java * * Created on 2007年11月13日, 下午11:03 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package 一对一聊天;import java.awt.*;import java.awt.event.*;import java.net.*;import java.io.*;/** * * @author baili */public class clientskt extends Thread{ Socket skt; InetAddress host; int port; BufferedReader theInputStream; PrintStream theOutputStream; String readin; ChatOneToOne chat; /** Creates a new instance of clientskt */ public clientskt(String ip,int p,ChatOneToOne chat) { try { host=InetAddress.getByName(ip); port=p; this.chat=chat; } catch(IOException e) { chat.ta.append(e.toString()); } } public void run() { try { chat.ta.append("尝试联机......"); skt=new Socket(host,port); chat.ta.append("联机成功\n"); theInputStream=new BufferedReader(new InputStreamReader(skt.getInputStream())); theOutputStream=new PrintStream(skt.getOutputStream()); while(true) { readin=theInputStream.readLine(); chat.ta.append(readin+"\n"); } }catch(SocketException e) { chat.ta.append("联机中断\n"); chat.tfaddress.setEnabled(true); chat.tfport.setEnabled(true); chat.clientBtn.setEnabled(true); chat.serverBtn.setEnabled(true); try{ skt.close(); } catch(IOException err) { chat.ta.append(err.toString()); } } catch(IOException e) { chat.ta.append(e.toString()); } } public void dataout(String data) { theOutputStream.println(data); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -