Fsocket char/string
Posted: Fri Sep 17, 2010 3:58 pm
All,
I am having trouble with an fsocket connection. I can use the code below without a hitch to grab the actual data. Were the problem lies is......I can only seem to read data from my device using FgetC. So it returns each character one by one because the other methods hang. I am ok with using this method but i would need to some how store each character returned and then make (combine) into one big string so I can manupulate later on. Now I know there are the functions of Socket_recv, which seems like what would be ideal to use. My device does not send a LF command but rather a carriage return only. Can someone post an example of socket_receive that accepts data until a carriage return is sent. I am not opening a file, this is data streaming from a device (ip-rs485). If this is not possible then can someone post an example of how to put the characters all in one string using the code below. Thanks so much!
$current_line = fgetc($fp);
while (!feof($fp)) {
// process current line
$current_line = fgetc($fp);
if($current_line === "\r") break;
echo $current_line;
}
fclose($fp);
I am having trouble with an fsocket connection. I can use the code below without a hitch to grab the actual data. Were the problem lies is......I can only seem to read data from my device using FgetC. So it returns each character one by one because the other methods hang. I am ok with using this method but i would need to some how store each character returned and then make (combine) into one big string so I can manupulate later on. Now I know there are the functions of Socket_recv, which seems like what would be ideal to use. My device does not send a LF command but rather a carriage return only. Can someone post an example of socket_receive that accepts data until a carriage return is sent. I am not opening a file, this is data streaming from a device (ip-rs485). If this is not possible then can someone post an example of how to put the characters all in one string using the code below. Thanks so much!
$current_line = fgetc($fp);
while (!feof($fp)) {
// process current line
$current_line = fgetc($fp);
if($current_line === "\r") break;
echo $current_line;
}
fclose($fp);