dispatch for both client and server