Rewrite socket connection