I did this about 6 years ago so there may be a better way to do it these days. But I created a ServerSocket with an associated thread to catch incoming client requests. I created a kind of ad hoc protocol that was something like the first 3 characters of data a client sends would instruct the server and client on how to how to handle the data that followed (like PM, posting message, change chat rooms, etc.) with a special char to indicate the end of a character.
The server maintains a list of current client connections and each client connection can has a state set such as which chat room the user is currently in or if they are AFK or whatever feature you choose to implement. This list is used to know who to send messages to and whatever.
Remember to make everything thread safe as once more then a few people enter the chat there can be quite a few threads flying around.
Again this is just kind of throwing something together and what I created was far from a polished application. But hopefully it'll give you some idea's on how to proceed.