Java 多客户端即时消息概念帮助
我正在尝试实现一个Java聊天程序。在此程序中,多个客户端将通过服务器相互通信。服务器将消息从一个客户端转发到另一个客户端。它还将提供好友列表的更新。从概念上讲,实现此 IM 聊天的最佳途径是什么。我遇到问题的部分是让服务器将消息从一个客户端中继到另一个客户端。每个客户端还应该能够选择他们想要与谁交谈。服务器的唯一目的还是从一个客户端获取消息并将其发送到另一个客户端。如果一个客户端连接到服务器,则在另一客户端连接之前不会发生任何事情。然后两个客户端开始相互通信。
I am try to implement a Java chat program. In this program multiple clients will talk to each other via a server. The server will relay messages from on client to another. It will also provide updates to a buddy list. Conceptually what would be the best route to take to implement this IM chat. The part I am having trouble with is making the server relay messages from one client to another. Each client should also be able to choose who they want to talk to.Once again the only purpose of the server is to take messages from one client and send it to another client. If one client is connected to the server nothing happens till another client connects. Then both clients begin to communicate to each other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要想出一个实施协议;查看XMPP。部分问题是确定您将向哪个其他用户发送消息。 XMPP 有助于解决这个问题。我建议连接到服务器的每个用户都有一个线程来处理连接。然后,您可以将所有线程存储到 HashMap 中,其中键是用户名。然后只需将消息推送到线程实现上,该线程实现会将消息发送到客户端。
You'll need to come up with implementing a protocol; check out XMPP. Part of the issue is determining which other user you will be sending the message to. XMPP helps to solve that issue. I would suggest that each user that connects to the server would have a thread to handle the connection. Then you can store all of the threads into a HashMap where the key would be the username. Then just push messages onto the thread implementation which would send the message(s) to the client.
对于基本的聊天系统,您将需要以下功能:
For a basic chat system you will want the following features: