import java.io.*;
import java.net.*;
public class ChatClient {
public static void main(String argn[]){
try{
Socket socket=new Socket("127.0.0.1",4000);
System.out.println("输入你要说的话,如果要退出输入bye");
BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
PrintWriter os =new PrintWriter(socket.getOutputStream());
BufferedReader is =new BufferedReader(new InputStreamReader(socket.getInputStream()));
String readline;
readline=sin.readLine();
while(! readline.equals("bye")){
os.println(readline);
os.flush();
System.out.println("Client:"+readline);
System.out.println("Server:"+is.readLine());
readline=sin.readLine();
}
os.close();
is.close();
socket.close();
}catch(Exception e){
System.out.println("Error"+e);
}
}
}
ChatClient代码
最新推荐文章于 2022-08-15 20:06:25 发布