add handle message function for server and client