If I understand correctly, you are wondering how can the server let user B know *in real time* that a new message has been typed in the chat. Essentially, you are looking for a kind of server push technology.
There are multiple solutions to this, but I suggest you take a look at implementing a Comet-style system (see here
). That's what a lof of interactive web sites use to notify users of server events in real-time (Facebook's chat for instance is based on Comet). We use it ourselves for our Collaba platform's live chat module.
The beauty of Comet-style communication is that it's quite easy to implement and does not require Flash, Java or any browser plug-in. It just works with plain Ajax.