safe socket receive and send using size information