Factorize receiving message from socket