better modularized socket server and client