On 04 Feb 2005 19:24:29 -0800, Paul Rubin <> wrote:
> Tom Brown <[EMAIL PROTECTED]> writes:
...
> Why don't you look at the struct module instead. You could also look
> the xdr or xmlrpc libraries, which may be closer to what you want.
Or look at existing, successful standards like HTTP, SMTP, et
Use string formatting :
msglen = '%16s' %len(testmessage)
will return a 16-byte string, beginning with spaces. Send it over your
connection and use int() to get the message length
Pierre
--
http://mail.python.org/mailman/listinfo/python-list
Tom Brown <[EMAIL PROTECTED]> writes:
> However, in my actual program I will not know the length of testmessage in
> advance. So how do I convert msglen into a suitable format for the send
> method?
>>> str(123)
'123'
You might also look at
http://cr.yp.to/proto/netstrings.txt
whi
Tom Brown <[EMAIL PROTECTED]> writes:
> Ok, I think I've found what I was looking for. The marshal.dumps()
> function will convert my integer into a string representation of a
> fixed size. This way, on the other side, I know how many bytes to
> read to get the size of the string.
Think hard about
On Friday 04 February 2005 18:27, Tom Brown wrote:
> Hi,
>
> I have what seems to be a simple problem. But I can not for the life of me
> find a way to send an integer over a socket. The send method will only
> accept strings. Here is what I am trying to do:
>
> testmessage = 'test message'
> msgle
Hi,
I have what seems to be a simple problem. But I can not for the life of me
find a way to send an integer over a socket. The send method will only accept
strings. Here is what I am trying to do:
testmessage = 'test message'
msglen = len(testmessage)
sock.send(msglen)
sock.send(testmessage)