extract common callback between server & client