How Instant Messaging Works
sends a request to the IM server telling it that you are online. If a friend connects, the IM server sends a packet to your IM client and vice versa
If a chat session has more than two clients, multiple packets are sent by the IM server. IM servers can also relay information to other IM servers.
When you type some text, your IM client sends the text in a packet to the IM server which relays it to your friend.