Jump to content
  • Advertisement
Sign in to follow this  
Uncivil

Python sendto sizes.

This topic is 5114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a quickie Python program that sends test data to a running C application over a network. Specifically I'm sending 3 floats using a SOCK_DGRAM socket like this:
data = struct.pack('!3f', f1, f2, f3)
sock.sendto(data, addr)


The length of data is 12. But the C application receives 16 bytes. The C code also uses a SOCK_DGRAM and looks like this:
sockaddr from;
socklen_t len = 0;
int buffsize = 12;
char buff[buffsize];
recvfrom(sock, (void*)&buff, buffsize, 0, &from, &len);

The first 12 bytes that is received is the correct data so it seems an extra 4 bytes is tacked on somewhere along the way. By the way only 12 bytes are received if Python is used to receive the data.

Share this post


Link to post
Share on other sites
Advertisement
How is that C code receiving 16 bytes when you tell it to receive 12? Do you receive the EMSGSIZE error code? If you're thinking about the 'len' parameter, that's telling you how long the sender's address is, not how long the data sent is. A generic socket address is indeed 16 bytes long. The amount of data read however is the return value from recvfrom().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!