Modularized connection code in client and server