The first message you send after the very next moment you login will be sent to the other user but it will not be visible to that guy until he refreshes his page.
The last message you send just before you logout will not be visible to you the next time you login. You need to refresh once.
When a user is offline and someone sends msgs to that user, they will be stored in that offline user's wait queue and be flushed to him when he comes back online again.
๏ปฟ* But that is not happening here. When a user logs in, he cannot see those messages that were sent to him when he was offline, just yet.
But if he refreshes the page once, he can see all the messages nicely.
The same is happening with socket events stored in waitqueues.