0

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.

Edited by Nick Evan: Fixed formatting

1
Contributor
2
Replies
3
Views
6 Years
Discussion Span
Last Post by karthik_ppts
0

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.