added try-catch block for socket error