Check for successful connect.

Fixes segmentation fault.