Historically, people from different regions would be able to read each other's writing (send letters to each other) even if their spoken dialects/languages were mutually incomprehensible. You get this in European history, too, just not to the same degree.
Usually from contexts. If datastream could be interpreted as "correct horse battery staple" or "add salt to taste" and the situational context is a cooking instruction, the latter interpretation has to be correct.
Then how can Chinese speakers understand each other when they speak?