//Client.java客户端
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class Client {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Socket client = new Socket("localhost",8888);
new Thread(new ClientThread(client)).start();
BufferedReader buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
boolean flag = true;
while(flag){
String rec = buf.readLine();
System.out.println(rec);
}
}
}
class ClientThread implements Runnable{
private Socket client = null;
public ClientThread(Socket client){
this.client = client;
}
public void run(){
try{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
PrintStream out = new PrintStream(client.getOutputStream());
while(true){
String content = input.readLine();
out.pr
java简单的控制台聊天室
最新推荐文章于 2024-07-06 11:37:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)