资源简介
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;
}
}
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 15786 2018-11-08 11:57 javaQQ聊天室.docx
----------- --------- ---------- ----- ----
文件 15786 2018-11-08 11:57 javaQQ聊天室.docx
评论
共有 条评论