[Tutor] confusion and problems with first socket script
Xavier Combelle
xcombelle at kedros.com
Thu Feb 19 08:10:08 EST 2004
Maybe other people are better than me in networking,
but I found a kind of answer, I give you as it is
Hameed Khan a écrit :
># According to documentation the argument to listen()
>is the number of connections we can accept at one
>time.
>
>
Apparently, the backlog argument is the number of queued connection
and not the total number of connection accepted.
*listen*( backlog)
Listen for connections made to the socket. The backlog argument
specifies the maximum number of queued connections and should be at
least 1; the maximum
value is system-dependent (usually 5).
One solution to accept just one connection at time and not create a new
thread to handle it
> while True:
> conn, addr = serversock.accept()
> print "Client Connected:", addr
> thread.start_new_thread(handConnect, (conn,))
>
>
>
while True:
conn, addr = serversock.accept()
print "Client Connected:", addr
handConnect (conn)
>if __name__ == "__main__":
> main()
>
>
>
>
And if you don't want the client
you can add a time out just before the connection
sock.settimeout(3.0)
>sock.connect((host, port))
>
>
More information about the Tutor
mailing list