socket.getsockname is returning junk!!

Wong Wah Meng-R32813 r32813 at freescale.com
Wed Oct 5 07:56:08 EDT 2011


Hello guys,

I am migrating my application from python 1.5.2 to 2.7.1. One of the existing code breaks. The getsockname method from socket object somehow returns me with some number which I deem as junk, rather than the listening port as I would have expected in the older python. Has anyone seen the same thing or is it due to my python is built with some corrupted library or something?


$ python
Python 2.7.1 (r271:86832, Oct  5 2011, 18:34:15) [C] on hp-ux11
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
>>> sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
>>> sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1 )
>>> sock.setsockopt( socket.IPPROTO_TCP, 1, 1 )
>>> server_address=('zmy02hp3', 11111)
>>> sock.bind(server_address)
>>> sock.getsockname()
(0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

In python 1.5.2
>>> server_address=('zmy02aix04', 11111)
>>> sock.bind(server_address)
>>> sock.getsockname()
('10.228.51.41', 11111)
>>>


Regards,
Wah Meng

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111005/e0652b1e/attachment.html>


More information about the Python-list mailing list