📄 serverskt.java
字号:
/* * serverskt.java * * Created on 2007年11月13日, 下午11:14 * * 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 serverskt extends Thread{ ServerSocket skt; Socket Client; TextArea in; BufferedReader theInputStream; PrintStream theOutputStream; String readin; ChatOneToOne chat; /** Creates a new instance of serverskt */ public serverskt(int port,ChatOneToOne chat) { try { skt=new ServerSocket(port); this.chat=chat; } catch(IOException e) { chat.ta.append(e.toString()); } } public void run() { try { chat.ta.append("等待联机......"); Client=skt.accept(); chat.ta.append("客户端"+Client.getInetAddress()+"已联机\n"); 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.tfaddress.setEnabled(true); chat.tfport.setEnabled(true); chat.clientBtn.setEnabled(true); chat.serverBtn.setEnabled(true); try{ skt.close(); Client.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 + -