packageChatRoomTCPQQ谈天室;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.PrintWriter;importjava.net.Socket;importjava.net.UnknownHostException;importjavax.swing.JOptionPane;publicclassChatRoomClent{privateSockets;publicChatRoomClent(Stringhost,intport){try{s=newSocket(host,port);}catch(UnknownHostExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}}publicvoidsendMessage(Stringstr){PrintWriterpw=null;try{pw=newPrintWriter(s.getOutputStream());pw.println(str);pw.flush();}catch(IOExceptione){e.printStackTrace();}}publicStringreciveMessage(){BufferedReaderbr=null;Stringstr="";try{br=newBufferedReader(newInputStreamReader(s.getInputStream()));str=br.readLine();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnstr;}}
1