Typically, a message socket is created, used, then destroyed. Only listener sockets are persistent. Hence, your chat should work something like this:
server
receive user validation (login) request -- respond with cookie or reject
receive user message (cookie + text) request -- replicate text to all logged-in users
receive user logout request -- cookie no longer valid, user removed from logged-in user list
In both the server and the client, you will have to set up a listener socket that accepts connections to the program, performs the above on the new connection, then closes the new connection; and continues to listen for more connections.
Now, I'm no expert in this field -- so there could easily be other ways to do this...