1

I am trying to send an integer value from a server written in Python to a client written in C and when I convert the int value to htonl to send to the C like this:

size = bytes(socket.htonl(len(input)))

it returns this error: Protocol wrong type for socket for this line:

recv = connection.send(size)

How can I send an integer value over to the client in C in this way or is there an easier way?

2
  • 1
    Please add your entire code. Commented Jan 26, 2020 at 0:33
  • 1
    The error you see has nothing to do with the serializing of the integer. The question is missing the necessary context to find out what really is causing the problem. Commented Jan 26, 2020 at 7:48

1 Answer 1

1

In the future please provide all relevant information: python version, OS, backtrace, and, in this instance, the code that created the socket.

This article probably explains what is happening:

http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/

Which means you probably have a bug in your server and/or client code that causes the connection to be torn down at an inopportune moment.

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

4 Comments

I don't see how you can possibly get that on a send. Connect, yes, send no.
@user207421 Yes, that should be impossible on a send(). I was more or less parroting another stackoverflow answer that seemed relevant. However, digging deeper I think the real issue is a quirk of macOS. I've updated my answer.
VG. Bizarre post you cited. All errno values originate inside the kernel, not in user space, and this is indeed a bug, not a 'poorly documented edge case.' It should have given EPIPE.
@user207421 You're mistaken. It is rare, but not unheard of, for functions in, for example, libc to explicitly set errno.

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.