This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author GeorgeY
Recipients GeorgeY
Date 2016-10-15.01:13:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1476493997.73.0.778740758656.issue28447@psf.upfronthosting.co.za>
In-reply-to
Content
I need to know the IP address on the other side of a broken TCP/IP connection. 

"socket.getpeername()" fails to do the job sometimes because the connection has been closed, and Windows Error 10038 tells the connection is no longer a socket so that the method getpeername is wrongly used.

Here goes the code in main thread:
-----------
mailbox = queue.Queue()

read_sockets, write_sockets, error_sockets = select.select(active_socks,[],[],TIMEOUT)
for sock in read_sockets:
......
    except:
        mailbox.put( (("sock_err",sock), 'localhost') )
=========

The sub thread get this message from mailbox and try to analyze the broken socket, to simplify I put the code and output together:

-------------
print(sock)>>>
<socket.socket [closed] fd=-1, family=AFNET, type=SOCKSTREAM, proto=0>
sock.getpeername()>>>
OS.Error[WinError10038]an operation was attempted on something that is not a socket
=======

Surprisingly,  this kind of error happen occasionally - sometimes the socket object is normal and getpeername() works fine.

So once a connection is broken, there is no way to tell the address to whom it connected?
History
Date User Action Args
2016-10-15 01:13:17GeorgeYsetrecipients: + GeorgeY
2016-10-15 01:13:17GeorgeYsetmessageid: <1476493997.73.0.778740758656.issue28447@psf.upfronthosting.co.za>
2016-10-15 01:13:17GeorgeYlinkissue28447 messages
2016-10-15 01:13:16GeorgeYcreate