0

I want to send an array using a UDP connection. When I use the sendto function, it complains that it must be a string. Is there any way around this?

Thanks

1 Answer 1

1

You must serialize your data (in this case is an array) before sending it. Then in receiver, you will deserialize to get the original data.

You can do it in Python, using pickle or cPickle module:

import cPickle as p

# Sender
data_str = p.dumps(array)
sock.sendto(data_str, addr)

# Receiver
data,addr = sock.recvfrom(buf)
data_origin = p.loads(data)
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.