Basic routines for socket connection