Re: Socket_Connect returning unusual error
| From: | Adam Hubscher | Date: | Mon, 17 Jan 2005 03:28:02 +0000 |
| Subject: | Re: Socket_Connect returning unusual error | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206505@lists.php.net to get a copy of this message | ||
Richard Lynch wrote:
Adam Hubscher wrote:However,now I get the error: Couldn't Create Socket: Transport endpoint is already connected after it successfully connects once already. The new code is found in my other post (socket_connect errors), but for reference: if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){Warning: socket_connect() expects parameter 3 to be long, string given in testing.php on line 21 Couldn't Create Socket: SuccessPHP usually auto-converts data -- However it's possible that this EXPERIMENTAL function (?) doesn't have the magic code down in the guts of PHP. So, try type-casting your third parameter to an (int):$currport = (int) $servers[$key]['Port']; echo "currport is: '$currport'<br />\n"; If this fixes it, file a bug report at http://bugs.php.net -- search for the same issue first. It should get fixed pretty quick-like (relatively speaking) if that's all it is. It's also possible that your 'Port' is empty or something... That's why I included the 'echo' -- Always hand-check the data you are sending when weird things happen. One line of debugging output can save hours of time and fistfuls of hair. I actually fixed it by using a simple preg_replace to remove any returns/spaces. It was actually imported from a text file and I forgot to clean up any excess characters taht could still exist.$currport = $servers[$key]['Port']; // was attempting this to see
print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n");
}
socket_set_option($sock, SOL_SOCKET,SO_RCVTIMEO, array('sec' => 1, 'usec' => 0));
$output = '';
for($i = 0; $i < count($file); $i++){
$servernum = $file[$i];
$i++;
$servername = $file[$i];
$serverport = $file2[$i];
$serverport = preg_replace('/\s/','',$serverport);
// Test if server online - if not, output offline. If yes, output Online.
if(!socket_connect($sock, $ip, $mapport)){
print("Couldn't Create Socket: " . socket_strerror(socket_last_error()). "\n"); // Debug
$output .= "Server Name: " . $servername. " ~~ Offline <br />";
continue;
}
else{
$output .= "Server Name: " . $servername. " ~~ Online <br />";
}
}