I am checking for open/closed status of ports on a PC using:
1 $fp= fsockopen("udp://host", port, &errno, &errstr);
2 fwrite($fp,"\n");

My ZoneAlarm firewall (if its on) shows an alert & blocks on the second line.
With firewall on or off, I never get an error message. With firewall off, I was expecting an error message on a closed port (port unreachable?).
I have tried an fread($fp, 1) with no success.
What can I add to determine if a UDP port on a PC is open or closed?
Thx, Doug

    $fp = fsockopen("udp://host", port, &$errno, &$errstr);
    if (!$fp)
    {
    echo "ERROR: $errno - $errstr<br>\n";
    }
    else
    {
    fwrite($fp,"\n");
    }
    fclose($fp);

    if the conenction doesnt work you will get the error msg printed to the browser which u can then look up and debug further.

      Thx, Andrew, I did try that but I always get errno=0 (no error) whether the port on my PC is open or closed.

        error 0 doesmt mean no error it means there was a problem with the connect() call. That is most likely due to a problem initializing the socket.

        And i have no idea waht to beyond that have u tried using other protcols on the scoket to see if it is the protcol thats the prob or a problem with ur firewall clsoing the socket. I not to sure to be honest since i seem to have problems with UDP since i cant read beyond 140 chars yet the server wrote more thasn that. odd. Soz i cant be much help but network programming is often done in php so i couldnt find much help with it. 🙁

          Write a Reply...