简体   繁体   中英

PHP Socket connection - Connection Refused

I have a simple PHP script to connect to a remote VB.NET server application on port 9999. I can telnet (on port 9999) from the web to External IP address & port but I can not get the script to connect - keep getting Connection Refused. Port 9999 is open & Sockets is enabled in PHP.

<?php
$host="<IP Address>" ;
$port=9999;
$timeout=30;
$sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ;
if (!is_resource($sk)) {
    exit("connection fail x: ".$errnum." ".$errstr) ;
} else {
    fputs($sk, "hello world") ;
    $dati="" ;
    while (!feof($sk)) {
        $dati.= fgets ($sk, 1024);
    }
}
fclose($sk) ;
echo($dati) ;
?>

Help - What am I doing wrong?

This works when I test it locally with netcat listening on port 9999... so, nothing. The problem is either in the middle or on the other side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM