0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.