You shouldn't create a new Socket
to send a message. Instead, use a socket of an existing connection.
The sequence should be the following:
- Client A connects to the server (server stores the connection as SocketA).
- Client B connects to the server (server stores the connection as SocketB).
- Server reads a private message from SocketA. The message is addressed to client B.
- Server finds the existing socket for client B. It's SocketB.
- Server sends the message into SocketB.