文件名称:javaQQ聊天室+SocketTCP
文件大小:15KB
文件格式:DOCX
更新时间:2015-03-14 02:38:52
SocketTCP,javaSocket,java,javaQQ聊天室,javaQQ
package ChatRoomTCPQQ聊天室; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JOptionPane; public class ChatRoomClent { private Socket s; public ChatRoomClent(String host,int port){ try { s=new Socket(host,port); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void sendMessage(String str){ PrintWriter pw=null; try { pw=new PrintWriter(s.getOutputStream()); pw.println(str); pw.flush(); } catch (IOException e) { e.printStackTrace(); } } public String reciveMessage(){ BufferedReader br=null; String str=""; try { br=new BufferedReader(new InputStreamReader(s.getInputStream())); str = br.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; } }