Add buffering in socket and use it to read messages.