added try catch to socket calls