Improve debug messages to be 32/64 bit C99 compliant
Add a forgotten connection in one direction.

Factorize the connection code.
Use a more compact port allocation.