[Tutor] bind problem

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Sep 15 20:49:13 CEST 2004



On Wed, 15 Sep 2004, Kevin wrote:

> I can't seem to find what is wrong here I keep getting this error:
> Traceback (most recent call last):
>   File "./mmaker.py", line 39, in ?
>     server =3D3D sServer.Server(port, world)
>   File "./sServer.py", line 29, in __init__
>     self._sock.bind(' ',port)
> TypeError: bind() takes exactly one argument (2 given)
>
> I have also attached the files for anyone to take a look at. If anyone
> could help me out and tell me what whent wrong that would be great


Hi Kevin,

It looks like you're making a connection using stuff from the 'socket'
module.

    http://www.python.org/doc/lib/socket-objects.html


According to the documentation on bind():

"""
bind()

Bind the socket to address. The socket must not already be bound. (The
format of address depends on the address family -- see above.) Note: This
method has historically accepted a pair of parameters for AF_INET
addresses instead of only a tuple. This was never intentional and is no
longer available in Python 2.0 and later.
"""

The very last part is the important part.  At the moment, the initializer
of your server is calling:

    self._sock.bind(' ',port)

and this doesn't work: you need to modify this to pass a 2-tuple instead.
Like this:

    self._sock.bind( (' ',port) )


See:

    http://www.python.org/doc/lib/socket-example.html

for an example.  In this particular case, the parentheses are significant.


That being said, since we're using AF_INET, I thought that bind had to
take a 2-tuple of the host and the port.  Is it ok to leave the 'host'
part blank?


Good luck to you!



More information about the Tutor mailing list