I just want a very simple client to connect and read data from a TCP server that I know its up and running fine.
Here’s my piece of code:
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
if(!socket_connect($sock , 'my.ip.goes.here' , port))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
I get the socket created fine, error when connecting though: “Could not connect: [110] Connection timed out”
Edit: Could it be a problem with my host? If so, I could try finding the problem there.
Edit: My host seems fine, it does allow sockets to be used. Any more tips?
Cannot test it right now, but probably it’s because you didn’t specify the protocol. In this case,
will do the trick…