socket send

Mark Tolonen metolone+gmane at
Thu Jul 30 09:56:07 EDT 2009

"NighterNet" <darkneter at> wrote in message 
news:55aba832-df6d-455f-bf34-04d37eb061cd at
>I am trying to figure out how to send text or byte in python 3.1. I am
> trying to send data to flash socket to get there. I am not sure how to
> work it.
> buff= 'id=' , , ':balive=False\n'
> clientSock.send(buff);
> -- 

Python 3.1 strings are Unicode (think characters not bytes).  When writing 
to files, sockets, etc. bytes must be used.  Unicode strings have an 
encode() method, where you can specify an appropriate encoding (ascii, 
latin-1, windows-1252, utf-8, etc.):


When reading from the socket, you can decode() the byte strings back into 
Unicode strings.

    data = clientSock.recv(1024).decode('ascii')


More information about the Python-list mailing list