sockets
dj trombley
badzen at yifan.net
Sun Dec 19 02:25:01 EST 1999
sameer chowdhury wrote:
>
> Hi everyone:
>
> The first time I connect a client and a server using sockets, it works fine,
> I then close both sockets. But the second and subsequent times, I get the
> following error, even if I change the ports for both the client and the
> server. Can anyone tell me what the reason could be? I am using Win98, and
> running python 1.5.2.
>
> Error:
>
> Traceback (innermost last):
> File "client_stuff.py", line 6, in ?
> s.connect(HOST, PORT)
> File "<string>", line 1, in connect
> socket.error: (10061, 'winsock error')
>
> client:
>
> # Echo client program
> from socket import *
> HOST = 'localhost' # The remote host
> PORT = 81 # The same port as used by the server
> s = socket(AF_INET, SOCK_STREAM)
> s.connect(HOST, PORT)
> s.send('stuff')
> data = s.recv(1024)
> s.close()
> print 'Received', `data`
>
> server:
>
> # Echo server program
> from socket import *
> HOST = 'localhost' # Symbolic name meaning the local host
> PORT = 81 # Arbitrary non-privileged server
> s = socket(AF_INET, SOCK_STREAM)
> s.bind(HOST, PORT)
> s.listen(1)
> conn, addr = s.accept()
> print 'Connected by', addr
> while 1:
> data = conn.recv(1024)
> if not data: break
> conn.send(data)
> conn.close()
Winsock error 10061 is a CONNECTION_REFUSED.
It is not clear from the above exactly what you are doing to
"close both sockets" (there are three!) or to connect them a second
time, so
perhaps more detail is needed. I assume you realize that after
accept()'ing a connection, the server socket is still active and
can accept() further connections.
-dj
Dave Trombley
<badzen at yifan.net>
More information about the Python-list
mailing list