Reputation: 13
I am wondering How to send two variables in python socket. I am currently doing it but the way in which I am sending them can make it so if it misses one send then they switch which variable is which, which is very bad for my purpose. Is there a way I can label the variables so I send both kinda as if I were to label a variable y and on x send the variable with the label and then separate it on the other side, Is there a way to do this?
Upvotes: 0
Views: 1122
Reputation: 4940
This question is more about communication protocols than about python programming.
If you want reliable communication, use TCP sockets rather than UDP. Also, encode your messages in a form that keeps the identity of what you're sending together with the values.
JSON based example:
import json
sock.send(json.dumps({"x":x, "y":y}))
Also, you could consider a communications framework like ZeroMQ to take care of the data delivery for you.
Upvotes: 3