Hi Friends,
I need to get the data from the port that sent by an external device connected to my server's IP. I found the data sent by the device in my server using the TCP Port listner . Now i need to get the data to store in mysql.
This is code that i used.

<?php
    $host = "122.165.218.14";
    $port = 4321;
    set_time_limit(0);
    echo "Start to Create() socket....";
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("create():".socket_strerror(socket_last_error($socket)));
    echo "Start to Bind() Socket....";
    $result = socket_bind($socket, $host, $port) or die("Bind():".socket_strerror(socket_last_error($socket)));
    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);
?>

But it shows "Start to Create() socket....Start to Bind() Socket....Bind():Cannot assign requested address" error.
Please help me to get the from port or where should i run this script to get the data.

This issue is solved by replacing the $host = "122.165.218.14"(internet static ip) with server's local ip.

Now the socket is created and bound but gives connection error while read. whats going wrong with this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.