[Twisted-Python] the magical port 0
![](https://secure.gravatar.com/avatar/812cc4936ca92a5ad9073f521a32b7fb.jpg?s=120&d=mm&r=g)
Hello, As you might know, binding to port 0, actually binds an unallocated port; but despite how useful this might be, twisted.net returns port 0 anyway. The fix is easy, and that is to set port = skt.getsockname()[1] right after it has been binded. I don't if this applies to win32, or any other platform, but I assume that it does. I have not done this in CVS, but I hope someone with more insight into twisted.net could do it :) phed www.informative.f2s.com (be gone evil .zip-hating provider)
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
I looked at this, but I think the current approach is best. Since servers are (optionally) persistent, the fact that server.port is 0 tells you that the next time the server is brought in from a persistent store, it may be on a different port. My suggestion for this application is to call through directly to server.socket.getsockname()[1] directly. On Friday 11 May 2001 16:26, you wrote:
-- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
I looked at this, but I think the current approach is best. Since servers are (optionally) persistent, the fact that server.port is 0 tells you that the next time the server is brought in from a persistent store, it may be on a different port. My suggestion for this application is to call through directly to server.socket.getsockname()[1] directly. On Friday 11 May 2001 16:26, you wrote:
-- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph
participants (2)
-
Glyph Lefkowitz
-
grolgh