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("服务器退出!转账转账b站源码clone");
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",源码源码netty过滤源码);
InputStream in=s.getInputStream();
DataInputStream din=new DataInputStream(in);
OutputStream out=s.getOutputStream();
DataOutputStream dout=new DataOutputStream(out);
dout.writeUTF("服务器你好!我是聊天聊天阿里Tdm源码客户端");
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();
聊天聊天}
聊天聊天}
聊天聊天}
聊天聊天2024-11-24 22:251552人浏览
2024-11-24 21:30277人浏览
2024-11-24 21:08691人浏览
2024-11-24 20:50764人浏览
2024-11-24 20:411621人浏览
2024-11-24 20:292805人浏览
今30)日白天氣溫持續回升,北部及東半部高溫約在18到21度,中南部約在22到25度,感受較為溫暖,不過氣象局提醒,入夜後各地還是寒冷,尤其西半部日夜溫差大,民眾應適時調整穿著,另外受到清晨輻射冷卻影
1.走进SWMM源代码——SWMM转GIS经验及工具分享2.GIS软件SharpMap源码详解及应用基本信息3.vb课ç¨è®¾è®¡ å ³äºGISç4.GIS之家整理GIS源码、地图
1.oll是什么意思2.怎么根据布林带判断股票买卖点,布林带选股注意事项有哪些3.股票boll指标详解图解4.boll突破上轨是什么oll是什么意思 OLL的意思为“输出低延迟”。 OLL是一