socket script from perl -> python

kettle Josef.Robert.Novak at gmail.com
Thu Feb 7 17:05:34 CET 2008


On Feb 8, 12:08 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> kettle wrote:
> > Hi I have a socket script, written in perl, which I use to send
> > audio data from one server to another.  I would like to rewrite
> > this in python so as to replicate exactly the functionality of the
> > perl script, so as to incorporate this into a larger python
> > program. Unfortunately I still don't really have the hang of
> > socket programming in python.
>
> Socket programming in Python is just like socket programming in C. I
> suppose with Perl it's the same.
True, but I'm not talking about the concepts, I'm talking about the
idioms, which in python I don't know.


>
> > # pack $length as a 32-bit network-independent long
> > my $len = pack('N', $length);
> > [...]
> > I've used python's socket library to connect to the server, and
> > verified that the first piece of data'r' is read correctly, the
> > sticking point seems to be the $len variable.  I've tried using
> > socket.htonl() and the other less likely variants, but nothing
> > seem to produce the desired result, which would be to have the
> > server-side message print the same 'length' as the length printed
> > by the client.
>
> Try struct.calcsize.
Thanks for the suggestion, I hadn't tried that one.

-joe


>
> Regards,
>
> Björn
>
> --
> BOFH excuse #88:
>
> Boss' kid fucked up the machine




More information about the Python-list mailing list