[PATCH] RPC: extract socket logic common to both client and server