change basic server function, make the server start listener into a function