adding common function for socket