receiving and sending messages in loop until completely sent or received