开发者

Java Multi-Client Instant Messenger concept help

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.


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:

  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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜