Implement a TCP chat client that connects to a server, sends messages, and receives messages in a separate thread.