Select on Win XP

Josiah Carlson jcarlson at nospam.uci.edu
Fri Mar 19 19:58:27 EST 2004


> Hi,
> Thanks for your response.
> Yep, I have checked that.
> I am running tcpdump, and can see the packet go out
> and the response come back.
> The python program also dumps the packet
> but only after two packets have been sent
> does select() return and I can read the first response packet.
> 
> Any other ideas why select() is hanging?

I'm not terribly familliar with the performance of UDP datagrams, but it 
could be that the underlying network driver may be holding your data and 
not sending it until it gets more.

My win 2k machine doesn't seem to be having issues, so I don't really know.

Simplifying the code, I got the following (which works on my machine). 
Does the below work on your machine?  If so, then it is probably not the 
socket communication.

  - Josiah

#begin code
import socket
import select
import threading
import time

MY_PORT = 9999
MY_ADDR = 'localhost'

timeout = 1

my_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
my_sock.bind((MY_ADDR, MY_PORT))

def server(count):
     ilist = []
     ilist.append(my_sock)
     while count:
         il,ol,el = select.select(ilist,[],[],timeout)
         if il != []:
             data, addr = my_sock.recvfrom(1024)
             print "Got data:", data
             count -= 1
         else:
             print "No input from select"

def client(count, data):
     for i in xrange(count):
         my_sock.sendto(data, (MY_ADDR, MY_PORT))
         time.sleep(timeout)

threading.Thread(target=server, args=(10,)).start()
client(10, "hello")




More information about the Python-list mailing list