getting data from a port in use

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


--- 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!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Python-list mailing list