I am trying to connect to a server using sockets, and echo the data back. The server I am trying to connect to below automatically sends back a string of text when a client connects. The client does not have to send anything for that string, so upon connecting, there should be a string of data echoed. Here is my code so far:
<?
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'207.38.11.34',29900);
while($data = socket_read($socket,2046,PHP_NORMAL_READ))
{
echo $data;
}
?>
My problem is that when I load the page with this code, it continously loads and never displays any data. I was reading some tutorials on where you have to use \r\n, but I have no idea where to put that without messing up my code.
If I take out this code:
while($data = socket_read($socket,2046,PHP_NORMAL_READ))
{
echo $data;
}
.. the page loads just fine. So I basically need a simple way to echo the data received.
Thanks.