On Mar 12, 10:13 pm, Tim Roberts <t...@probo.com> wrote: > Hans <hans...@gmail.com> wrote: > > >I'm thinking to write a code which to: > >1. establish tons of udp/tcp connections to a server > > What does "tons" mean? Tens? Hundreds? > > >my question is how should I handle receiving traffic from each > >connection respectively? > > You're really going to want to use "select". You can store the objects in > a dictionary where the key is the socket number. That way, you can use the > result of the select and get your network object directly. > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc.
I wrote code like this: main proc: import socket_thread #start 1000 connection while i<1000: my_socket=socket_thread.socket_thread(i,host,port) my_socket.send(some_data) my_socket.recv() socket_thread.py class socket_thread: def __init__: self.soc_handle=socket.socket(socket.IF_INET,socket.DGRAM) def send(data): self.soc_handle.send(data) def recv(): while 1: input_list,output_list,exec_list=select.select([self.soc_handle],[],[], 2) data=input_list[0].recv(2048) print data But it does not work as I hope. main proc can only initiate one thread and then trapped by it, cannot get out. I'm sure I missed something but I don't know. Thanks for any help. -- http://mail.python.org/mailman/listinfo/python-list