En Wed, 24 Dec 2008 03:59:42 -0200, greyw...@gmail.com <greyw...@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:

from socket import *
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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to