1.跪求一个Java编写的聊天聊天聊天多人聊天程序源代码
跪求一个Java编写的多人聊天程序源代码
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.BufferedReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.util.Date;
class Server
{
public Server()
{
try
{
ServerSocket s=new ServerSocket();
Socket ss=s.accept();
OutputStream out=ss.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
InputStream in=ss.getInputStream();
DataInputStream din=new DataInputStream(in);
System.out.print(din.readUTF()+"!");
dout.writeUTF("你已经连接到服务器"+"\t"+"你的地址:"+ss.getInetAddress()+"\t"
+"你的链接端口:"+ss.getLocalPort()+"\n");
new ReadMessage(din).start();
new SendMessage(dout).start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Server();
}
}
//接受客户端信息
class ReadMessage extends Thread
{
private DataInputStream din;
public ReadMessage(DataInputStream din)
{
this.din=din;
}
public void run()
{
String str;
try
{
while (true)
{
str=din.readUTF();
System.out.println(new Date().toLocaleString()+"客户端说:"+str);
if (str.equals("bye"))
{
System.out.println("客户端下线!");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
// 发出服务器信息
class SendMessage extends Thread
{
private DataOutputStream dout;
public SendMessage(DataOutputStream dout)
{
this.dout=dout;
}
public void run()
{
InputStreamReader inr=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(inr);
String str;
try
{
while(true)
{
str=buf.readLine();
dout.writeUTF(str);
if (str.equals("bye"))
{
System.out.println("服务器退出!源码源码源代手机直播源码");
System.exit(1);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.BufferedReader;
import java.net.Socket;
import java.io.IOException;
import java.util.Date;
class Client
{
public Client()
{
try
{
Socket s=new Socket("..1.2",聊天聊天聊天系统框架源码);
InputStream in=s.getInputStream();
DataInputStream din=new DataInputStream(in);
OutputStream out=s.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
dout.writeUTF("服务器你好!我是源码源码源代流量网站源码客户端");
System.out.println(din.readUTF());
new Thread(new SenderMessage(dout)).start();
new Thread(new ReaderMessage(din)).start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new Client();
}
}
class ReaderMessage implements Runnable
{
private DataInputStream din;
public ReaderMessage(DataInputStream din)
{
this.din=din;
}
public void run()
{
String str;
try
{
while(true)
{
str=din.readUTF();
System.out.println(new Date().toLocaleString()+"服务器说:"+str);
if (str.equals("bye"))
{
System.out.println("服务器已经关闭,此程序自动退出!聊天聊天聊天诱惑支付源码");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
class SenderMessage implements Runnable
{
private DataOutputStream dout;
public SenderMessage(DataOutputStream dout)
{
this.dout=dout;
}
public void run()
{
String str;
InputStreamReader inf=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(inf);
try
{
while (true)
{
str=buf.readLine();
dout.writeUTF(str);
if (str.equals("bye"))
{
System.out.println("客户端自己退出!源码源码源代虚幻引擎源码");
聊天聊天聊天System.exit(1);
聊天聊天聊天}
聊天聊天聊天}
聊天聊天聊天}
聊天聊天聊天catch (IOException e)
聊天聊天聊天{
聊天聊天聊天e.printStackTrace();
聊天聊天聊天}
聊天聊天聊天}
聊天聊天聊天}
聊天聊天聊天2025-01-19 22:541807人浏览
2025-01-19 22:501554人浏览
2025-01-19 22:421891人浏览
2025-01-19 22:202566人浏览
2025-01-19 21:551008人浏览
2025-01-19 21:402458人浏览
为全力保障广大市民和游客的饮食安全与身体健康,近日,北京市东城区市场监管局开展老字号旅游餐饮单位食品安全专项检查。图为执法人员在前门大街全聚德烤鸭店检查。中国消费者报记者董芳忠摄影报道责任编辑:温馨宁
太魯閣號出軌事故,發生至今已經880多天,但這幾天卻在事故車廂裡,找到一片疑似罹難者的頭蓋骨,罹難者家屬團體發言人王薇君抨擊,檢警蒐證流程不夠嚴謹。今9/1)天鐵路警察對事故車廂再度進行蒐證,沒想到又
1.带源码怎样弄进易语言2.求一个简单的易语言源码,取系统运行时间的带源码怎样弄进易语言 打开易语言 单击新建 -- 选择window窗口程序--此时出现一个窗口 双击进入代码编写区域 然后将