karthik_ppts 81 Posting Pro

Hi Frendz,
I need to create one socket programming to read data from port of my server using php and this is my code

<?php
$host = "192.168.1.5";
$port = 4321;
set_time_limit(0);

echo "Start to Create socket....<br>";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("create():".socket_strerror(socket_last_error($socket)));
if($socket)
{
    echo "Socket Created!<br>";
}

echo "Start to Bind Socket....<br>";
$result = socket_bind($socket, $host, $port) or die("Bind():".socket_strerror(socket_last_error($socket)));
if($result)
{
    echo "Socket Bound!<br>";
}

echo "Start to connect socket....<br>";
$conn=socket_connect($socket,"122.165.218.14",4321);
if($conn)
{
    echo "Socket connected!<br>";
}

while (TRUE)
{
    $input = socket_read($socket,1024);
    $input = trim($input);
    echo $input;

    ob_flush(); // use both ob_flush and flush to ensure
    flush(); // output is written to the browser window
}
socket_close($socket);
?>

Using this code, the socket is created and socket is bound but the socket is not connected. why? Whats going wrong with this?