Sending hex number as is

Irmen de Jong irmen.NOSPAM at xs4all.nl
Mon Mar 21 15:31:55 EST 2005


knguyen at megisto.com wrote:
> This question may be ased before, but I couldn't find the answer
> searching the archive.
> 
> Basically, I just want to send a hex number from one machine to the
> next:
> 
> for example
> 
> msg = "Length is "
> n = '\x81'
> msg += n
> sock.send(msg)
> 
> The problem is n's value is not fixed. For example,
> 
> msg = "Length is "
> n = len(somestring)
> msg += n  # This won't work of course, since n is int
> 
> How do I send this msg + n?
> 
> Thanks,
> Khoa
> 

Just send the number as a string?
(and parse it to an int again on the other side)

Or investigate the struct and/or pickle modules.

Alternatively, depending on the broader scope of what
you are doing, investigate a proper IPC library such
as Pyro.


--Irmen



More information about the Python-list mailing list