Handle sending and receiving messages