How can I find the port a server is listening on - at the commented
line in the code below. (ie self.serving_on_port_num =
????? )<br>
<br>
I have googled a lot. :-(<br>
<br>
------------------------------------------------------------------<br>
<br>
class BaseSrvr(SocketServer.ThreadingMixIn, SocketServer.TCPServer):<br>
def server_bind(self):<br>
"""Override server_bind to store the server name."""<br>
try:<br>
SocketServer.TCPServer.server_bind(self)<br>
host, port = self.socket.getsockname()<br>
self.server_name = socket.getfqdn(host)<br>
self.server_port = port<br>
except:<br>
print "*******server bind except************"<br>
<br>
class RequestHandler(SocketServer.StreamRequestHandler):<br>
def handle(self):<br>
self.incoming_port =
self.client_address[1] <br>
#===> self.serving_on_port_num = ?????<br>
# The number of the serving port not the connecting port<br>
<br>
def StartServer(port):<br>
server = BaseSrvr(('', int(port) ), RequestHandler )<br>
server.serve_forever()<br>
<br>
if __name__ == '__main__':<br>
<br>
StartServer(port) <br>
<br clear="all">------------------------------------------------------------------------------