socket send help

greywine at gmail.com greywine at gmail.com
Thu Dec 25 02:43:31 CET 2008


Chris & Gabriel,

Thank you so much.  My simple example now works.  It was very
frustrating that even the simple example didn't work, so your help is
most appreciated.

b'hello world' was the key.  As for the error, I do still get it with
3.0 final so I'll go ahead and report it.

John.

On Dec 24, 12:03 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 24 Dec 2008 03:59:42 -0200, greyw... at gmail.com  
> <greyw... at gmail.com> escribió:
>
> > New guy here.  I'm trying to figure out sockets in order to one day do
> > a multiplayer game.  Here's my problem:  even the simplest examples
> > don't work on my computer:
>
> > A simple server:
>
> > fromsocketimport *
> > myHost = ''
>
> Try with myHost = '127.0.0.1' instead - a firewall might be blocking your  
> server.
>
> > s.listen(5)                         # allow 5 simultaneous connections
>
> Not exactly: your server program only handles a single connection at a  
> time. The 5 above specifies how many connections may exist "on hold"  
> waiting for you to accept() them.
>
> >             connection.send('echo -> ' + data)
>
> That's fine for Python 2.6, but you must use b'echo -> ' with 3.0
>
> > And a simple client:
>
> > s.send('Hello world')               # send the data
>
> Same as above, should be b'Hello world' with Python 3.0
>
> > If I run testserver.py via the cmd prompt in Windows XP and then the
> > testclient.py program, I get the following error:
>
> > Traceback (most recent call last):
> >   File "C:\Python30\testclient.py", line 12, in <module>
> >     s.send('Hello world')               # send the data
> > TypeError: send() argument 1 must be string or buffer, not str
>
> The above error message is wrong (and I think it was corrected on the 3.0  
> final release; if you got it with 3.0 final, file a bug report at  http://bugs.python.org/)
>
> > This happens in 2.6 or 3.0 and with different example client & server
> > programs from the web.  What am I missing?
>
> The error above surely comes from 3.0; with 2.6 you should get a different  
> error (if it fails at all). Try again with 2.6.1. I didn't run the code  
> but it looks fine -- if you got it from a book or article, unless it  
> explicitely says "Python 3.0", assume it was written for the 2.x series.
>
> --
> Gabriel Genellina




More information about the Python-list mailing list