Search code examples
javaserversocket

Java socket Chat application


Hi I am looking for guidance in to building a chat application using socket, which allows clients to create rooms for other clients to join in and chat. I have build a chat application which works and clients can join in however clients are in one room and can not move around to other rooms. I have created a similar application with multiply rooms using rmi user can add rooms for other clients to join and chat. This time i want to practice using socket. Any sort of help or guidance to get me started would be great thank you.


Solution

  • As far as I can work out, you want to

    • connect via plain IO Sockets and perhaps blocking NIO with one reader thread per socket.
      • I suggest you have a handler class which wraps each socket.
    • use a text based protocol.
      • you need a command to add to a room, to remove froma room, to get a list of current rooms, and to send a message.
    • allow a single client to subscribe/listen/appear in multiple rooms at once
      • this means you need a set of handlers in each room.
    • you want to handle slow consumers and disconnects gracefully.