上传者: yanyinxi
|
上传时间: 2019-12-21 22:09:31
|
文件大小: 15KB
|
文件类型: zip
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;
}
}