Java 多客户端即时消息概念帮助

发布于 2024-10-27 13:24:09 字数 240 浏览 5 评论 0原文

我正在尝试实现一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦纸 2024-11-03 13:24:09

你需要想出一个实施协议;查看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.

停顿的约定 2024-11-03 13:24:09

对于基本的聊天系统,您将需要以下功能:

  1. 客户端登录到您的服务器。这使您可以识别客户并保留每个客户的好友列表。
  2. 客户端仅向服务器发送消息。
  3. 客户端只接收来自服务器的消息。
  4. 每条消息必须标识以下内容:
    1. 消息的收件人。
    2. 消息来源。
    3. 消息的文本。
    4. 也许;消息发送的时间和日期。
  5. 服务器需要跟踪对话;基本上是客户对的列表。
  6. 如果你想做群聊,那么转换将是客户列表的列表。
  7. 当客户端向服务器发送消息时,服务器应将其转发给会话中的所有其他客户端。
  8. 您可能想让服务器记录所有对话。
  9. 您至少需要 2 种消息类型;文本(即聊天)和邀请。

For a basic chat system you will want the following features:

  1. A client logs into your server. This allows you to identify the client and to keep friend lists for each client.
  2. A client only ever sends messages to the server.
  3. A client only ever receives messages from the server.
  4. Each message must identify the following:
    1. The recipient of the message.
    2. The source of the message.
    3. The text of the message.
    4. Maybe; time and date the message was sent.
  5. The server will need to track conversations; basically a list of client pairs.
  6. If you want to do group chats, then the conversion will be a list of client lists.
  7. When a client sends a message to the server, the server should forward it to all other clients that are part of the conversation.
  8. You probably want to have the server log all conversations.
  9. You will need at least 2 message types; text (i.e. chat) and invite.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文