implemented message handling between server and client