code shared by client and server