|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-07-09 07:48 UTC] tony2001@php.net
[2006-07-09 07:56 UTC] aeolianmeson at blitzeclipse dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 23:00:01 2025 UTC |
Description: ------------ I am connecting to myself and then closing, to sniff out available ports on my system that I can use-- I'm sure you're acquainted with this method. It should always produce a different port (nPort), since no connection is erected (because it's UDP), but it always returns that it is on the SAME port. Dustin Oprea Reproduce code: --------------- $n = 10; while($n--) { $strIP = $nPort = -1; $Socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($Socket, '172.0.0.1', 8400); socket_getsockname($Socket, $strAddr, $nPort); socket_close($Socket); print("> Available port: $strAddr:$nPort\n"); } Expected result: ---------------- It produces ten lines of output, that should each contain one unique, available port number. Actual result: -------------- Each line indicates the same port, even if a socket has been opened for listening on it. The problem I am having, therefore, is that I sniff the next available port from this code, and set up a listener on it. I then do the same thing again in order to open another listener on a different port, but it always returns to me the same port number, and I can not not bind it, obviously. Is this intended?