Could not connect to server

I just want to ask some help,why is it my client socket could not connect to our server. my socket server socket script is located in our own server,but my client socket script is located in the hosting site.so meaning that they are separated files.When I tried to send message to our server I get error could not connect to server.I don’t know if there is something wrong with our own server or in the hosting site configuration.that does not allow me to connect to our server.
I tried to transfer my client socket script to our server,I put it in the same directory of my server socket script.,then I tried to run my client socket script in the browser and it works fine the server can receive the message.I am just confuse if I put back my client socket script in the hosting site.it cannot connect to our server.

I appreciate someone can help me.

Thank you in advance.

here is the client script



<?php



    $host    = "xxx.xx.xx.xx";//I.P to our server
    $port    = xxxx;//port to our server


    $message =  "hello server!";
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\
");

    $result = socket_connect($socket, $host, $port) or die("Could not connect to server\
");

    socket_write($socket, $message, strlen($message)) or die("Could not send data to server\
");

    socket_close($socket);



?>




Try this:


<?php 
  error_reporting(-1); // maximum
  ini_set('display_errors', true);

[COLOR=#000000][COLOR=#0000BB]  $host [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"xxx.xx.xx.xx"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#FF8000]//I.P to our server 
  [/COLOR][COLOR=#0000BB]$port [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]xxxx[/COLOR][COLOR=#007700];[/COLOR][COLOR=#FF8000]//port to our server 
  // the rest of your script
[/COLOR][/COLOR]

With a bit of luck, if there are any errors they will show and be helpful in solving your problem.

Also check the Apache Server error file.

You can retrieve the socket_connect() error code using socket_last_error(), and you can get the error message by passing the error code to socket_strerror(). Could you tell me what the following outputs:

echo socket_strerror(socket_last_error());

@tpunt and @ John_Betong, The error is

Couldn’t connect to server: [110] Connection timed out

Thank you in advance.

Have you opened (or forwarded) the appropriate port on your router (the one the server sits behind) so that when the client attempts to connect from outside your LAN, it can get in? Also note that if your router uses NAT, you’ll need to specify the external IP address of the router, not the LAN address of your server.

If you get to a machine outside your LAN and try to telnet in to the IP and port of your server, does it connect?

If you get to a machine outside your LAN and try to telnet in to the IP and port of your server, does it connect?

Yes, I can telnet my server,I tried to run my client socket in my laptop even though I am in different network and I was successfully sent the message to my server,I think the problem is in in the hosting site.The one that host my webpage I think they block a certain port…