Python code to send and receive messages (packets)