replace socket functions