954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

get data from port

Hi Friends,[INDENT][/INDENT]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.[INDENT][/INDENT]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.

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

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

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 


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

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: