catch some exceptions
don't open socket in the main thread