client server question

John weekender_ny at yahoo.com
Mon Aug 15 05:07:57 CEST 2005


Thanks a lot,
I think I could modify this to get my work done.
--j

Chris Curvey wrote:
> import threading
> import logging
>
> ######################################################################
> class Reader(threading.Thread):
>     def __init__(self, clientsock):
> 	threading.Thread.__init__(self)
> 	self.logger = logging.getLogger("Reader")
>
>     #-----------------------------------------------------------------
>     def run(self):
>         self.logger.info("New child %s" %
> (threading.currentThread().getName()))
>         self.logger.info("Got connection from %s" %
> (clientsock.getpeername()))
>
> ####################################################################
> # set up a socket to listen for incoming connections from our clients
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> s.bind((host, port))
> s.listen(1)
>
> while True:
>     try:
>         clientsock, clientaddr = s.accept()
>     except KeyboardInterrupt:
>         raise
>     except:
>         traceback.print_exc()
> 	continue
>
>     client = Reader(clientsock)
>     client.setDaemon(1)
>     client.start()




More information about the Python-list mailing list