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.

    $host = "";
    $port = 4321;
    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

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.

Edited by Nick Evan: Fixed formatting

6 Years
Discussion Span
Last Post by karthik_ppts

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.