ntohl/htonl socket transfer between c and python

Peter Hansen peter at engcorp.com
Tue Jun 25 08:15:39 EDT 2002


"Eivind B. Nilssen" wrote:
> 
> I have a bit of a problem I cant seem to solve. I am new at
> programming python,
> and my task is to make a client in python for fetching data from a
> remote server written in c.
> 
> The buffer sendt to me from the server is generated as follows:
> 
> *(int*)&bfr[bix] = htonl(*(int*)&f); #where f is a float value
> 
> The buffer received in my python program is a lot of strange asciis
> I am not able to cast this buffer to an int or a long and this again
> makes
> me unable to apply the ntohl command.
> 
> Does anybody have an idea how to extract the data from this buffer?
> Do I have to write this part in C?

No, you don't have to write it in C.  But please, always, post
code snippets from your own code showing the problem.  If possible,
use the interactive console to execute a few of your methods and
show the resulting data, or add some print statements to the code
to make it clear what's happening.

Without code to look at, we're going to waste a lot of time 
providing answers "shotgun" fashion, only some of which will hit the 
mark...

-Peter



More information about the Python-list mailing list