I\'m making a peer-to-peer instant messaging application.
Currently, if UserA.pool.net says \"hello\" to UserB.pool.net, User A sees \"You: hello\" and User B sees \
The short answer is that if you really want User A and User B to see the same text, you can't rely on finding out your hostname yourself. You need User B to transmit their view of User A's hostname to User A and vice versa. Due to NAT, you won't be able to just check your own computer's hostname.
Alternatively, (Jonathon beat me to this in the question comments) you can have each user send their own private hostname as part of the connection handshake and use that to print messages on the remote end.