Fix some connection issues
Move some code from header to cpp file
Detect connection failure
Print connect error message
Fix port mapping
Fix segfault when endpoint connections fails