sneakyimp;11009539 wrote:
What makes you say that? You need to share the technical details with us if we are to understand exactly what's going on. I suspect this may be a problem with using UDP -- you are being exposed to the sequencing/routing/error stuff that is automatically handled with TCP.
Let's see if I can make the situation clearer...
I'm trying to insert temperature values in a DB. Said temperature values are provided by a probe. To retrieve the temperature values I have to send a command (555555#STATUS#) to the probe. That's why:
$fp = stream_socket_client("udp://my_ip:my_port", $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
fwrite($fp, "555555#STATUS#\n");
/*while (!feof($fp))
{
echo fgets($fp, 1024);
}*/
fclose($fp);
}
I know this code is working for a fact.
But the probe send the data (temperature values) not to ip that send the command (555555#STATUS#) but to the IP and Port that is set in the probe SETUP. So I have to create another socket in that IP address (IP that is set in the probe SETUP) to receive the data. That's why
$fp_r = stream_socket_client("udp://localhost:receive_port", $errno, $errstr, 30);
if (!$fp_r)
{
echo "$errstr ($errno)<br />\n";
}
else
{
while (!feof($fp_r))
{
var_dump(fgets($fp_r, 1024));
}
fclose($fp_r);
}
So adding those two parts, sending the command and receiving the data in the determined IP adress I currently have:
$fp_r = stream_socket_client("udp://receive_ip:receive_port", $errno, $errstr, 30);
if (!$fp_r)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$fp = stream_socket_client("udp://my_ip:my_port", $errno, $errstr, 30);
if (!$fp)
{
echo "Socket Send Message: $errstr ($errno)<br />\n";
}
else
{
fwrite($fp, "555555#STATUS#\n");
}
while (!feof($fp_r))
{
var_dump(fgets($fp_r, 1024));
}
fclose($fp_r);
}
This code is sending the command correctly but not receiving correctly but I'm not entirely sure about the receive_ip so that could be the problem... Unless you find something else wrong with the previous code...
Thanks for the help...