On 30 Lug, 18:06, NighterNet <darkne...@gmail.com> wrote: > On Jul 30, 6:56 am, "Mark Tolonen" <metolone+gm...@gmail.com> wrote: > > > > > > > "NighterNet" <darkne...@gmail.com> wrote in message > > >news:55aba832-df6d-455f-bf34-04d37eb06...@i4g2000prm.googlegroups.com... > > > >I am trying to figure out how to send text or byte in python3.1. I am > > > trying to send data to flashsocketto get there. I am not sure how to > > > work it. > > > > buff= 'id=' , self.id , ':balive=False\n' > > > clientSock.send(buff); > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > > Python3.1strings 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.): > > > clientSock.send(buff.encode('ascii')) > > > When reading from thesocket, you can decode() the byte strings back into > > Unicode strings. > > > data = clientSock.recv(1024).decode('ascii') > > > -Mark > > I am not sure how to use struct package. > Here an example for the input: > {id:1,playername:guest,x:100,y:50} > {id:2,playername:tester,x:100,y:50} > > struct.pack(? )
If your messages are ASCII, like it seems, forget about struct, which is for 'binary' message format. Format the string as you would in 2.6 ( using % or string.format for instance ) and then use encode as instructed. -- http://mail.python.org/mailman/listinfo/python-list