function to socket