Re: Socket_connect producing errors that show no reason

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:
Adam Hubscher wrote:

The code looks like this:

if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0){
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 />";
}
}


My problem now is that as it runs through the loop - it has a connection error. Warning: socket_connect() [function.socket-connect]: unable to connect [106]: Transport endpoint is already connected in status.php on line 17



maybe you should close the socket before trying to open it again? also where is $ip being set?


Even looking at examples, I cannot figure out why this error is being produced. I cannot close the socket at the end of the loop, as it would make any further attempts for online status impossible.


The socket_close($sock) is directly after the loop.

Thanks for any help!



Hm. Thats interesting. I attempted that the other day, however at that time it produced results that are... very similar to an infinite loop (continuously "loading page" on status bar, and when I hit stop the page had nothing loaded). I expected it to be the same - however it worked this time, beautifully in fact.

Thanks, you pushed me to try a second time :P

Thats interesting as well, however... I consulted one of my PHP books for when I was learning the changes in PHP5 and looked at the example for socket_connect, it shows an example for querying the Return to Castle Wolfenstein master server, storing the data in an array, and then without utilizing socket_close in any of the loops - it continues to conect to each server and query it for its status (players, settings, etc). That is why I didnt see much error in my code - the example showed it to be correct in my eyes.

Anyways, yea, thanks for the help!

($ip was set just above that codeblock, for testing purposes I was using a local IP - 192.168.1.68 to test for functionality.)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux