简体   繁体   中英

Writing a Java Chat Program (Need Advice)

I'm looking to write a chat program in Java that would have functionality along these lines.

  1. Clients connect to a Server
  2. The Server keeps a list of those connected and make sure their usernames are unique
  3. A Client can request a private chat where the clients would connect directly and NOT through the server.

My question is how would you implement #3? Would you need to make new sockets?

Let the server handle all chats. Make your own "protocols" so your client sends a package containing both the message and destination (user). This can be done with either sending Strings with information you can parse or whole objects. This way it's also pretty easy to create groups with certain users in, all handled by the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM