move socket code out of runtime.c