Manish Gupta wrote: > invoking something like following - > > sock.send(100) > > generates the following error - > > TypeError: send() argument 1 must be string or read-only buffer, not int > > > how can I work around this? I wish to write > msg-length on a stream socket.
in what form? sock.send(chr(100)) # single byte sock.send(str(100)+"\n") # ascii characters plus newline sock.send(str(100)+":") # netstring prefix sock.send("%08d" % 100) # eight ascii characters, null-padded sock.send(str(100).encode("utf-16")) # same, in utf-16 with bom sock.send(struct.pack("!i", 100)) # 32-bit integer in network byte order etc. (see the struct module documentation for more alternatives) </F> -- http://mail.python.org/mailman/listinfo/python-list