Fix several bugs about receivinig and sending protocol