Reputation: 795
I am trying to connect to my public IP address but to no success.
The port is open as checked using - http://www.yougetsignal.com/tools/open-ports/ and a request from this site (http://www.rexswain.com/httpview.html) works.
My problem is with this PHP code below. This used to work fine when used on my local network. Now I am using it on a web server.
Could the problem be with the web server to allowing the request to be sent or am I doing something wrong?
$ip = "MYIP";
$port = "600";
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
//socket_bind($sock, $ip, $port) or die ("cannot bind to address.");
echo($ip);
$state = socket_connect($sock,$ip, $port);
$error = socket_last_error();
$errorMsg = socket_strerror($error);
echo($errorMsg);
EDIT : The error in my comment below was derived with the socket_bind commented (Code edited to output the error)
Error : Connection timed out
Upvotes: 0
Views: 86
Reputation: 18825
This is wrong:
socket_bind($sock, $ip, $port) or ...
$state = socket_connect($sock,$ip, $port);
Bind binds the local address of the socket, it doesn't make sense to bind and connect to the same port. In general you do not want to bind in client mode. Remove the line completely, then you may get real error.
Upvotes: 1