created a factory for creating server and client