getting data from a port in use

Dana Marcusanu dmarcusanu at yahoo.com
Tue Feb 1 22:23:12 EST 2005


Yes. It hangs at accept. I always end up doing end task because it never
passes the "accept" statement. When I set the port I use netstat (netstat
-bn) to get the ports that are in use. I use PythonWin 2.4. I am still
puzzled about the fact that it runs fine for you.
You are right about using the work_socket instead of s. My program never
ran to that line so I did not notice the error.

Thank you, Dana
--- Tony Meyer <t-meyer at ihug.co.nz> wrote:

> > I am trying to use Python to get the data received at a 
> > specific port (in use) on my computer. I already tried below
> > code which seems to hang at the statement accepting
> > connections. 
> 
> Seems to hang, or does hang?  Using print statements will tell you
> whether
> that's where it's getting stuck or not.
> 
> > I don't know what else I can try. Any
> > suggestions will be welcome.
> > 
> > import socket, select, os 
> > 
> > PORT = 2005
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
> > s.bind((socket.gethostname(), PORT))
> > s.listen(1)
> > work_socket, addr = s.accept() 
> > data = s.recv(1024)
> [...]
> 
> This should be 'data = work_socket.recv(1024)'.
> 
> This script works for me with that change.  (i.e. I can run it with port
> 2005 already in use, connect to the port, and it will finish without
> error).
> 
> =Tony.Meyer
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 



More information about the Python-list mailing list