After posting a thread of fget , and noone could help me, i attempted a typical socket_create and read .
This is my code
$socket[0] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$socket[conn] = socket_connect ($socket[0], $uplink[host], $uplink[port]);
$time = time();
do {
$read[res] = trim(socket_read($socket[0], 1028));
sleep(2);
if ($read[res] < 0) {
$strerror = strerror($read[res]);
debug("read() failed: reason: $strerror");
if (strstr($strerror, "peer")) {
die("Connection Died\n");
}
continue;
}
/if ($read[res] == 0) {
continue;
}/
debug("IN: $read[res]");
continue;
} while (true);
function servraw($raw) {
global $socket;
$raw .= "\r\n";
socket_write ($socket[0],"${raw}", strlen ("${raw}"));
debug("OUT: ${raw}");
}
function debug($msg) {
global $debug;
if ($debug[show] == yes) {
echo("DEBUG: ${msg}\n");
}
}
this is the result i got upon connecting.
DEBUG: IN: STRING A
STRING B
STRING C
STRING D
STRING E
Realise that it didn't get parsed by DEBUG after that.
I tried putting a sleep(2) after each socket_read, and this is the result
DEBUG: IN: STRING A
STRING B
DEBUG: IN: STRING C
DEBUG: IN: STRING D
STRING E
STRING F
It seems that the host i am connecting to is sending me multiple lines at a time, how do i ask the socket to read till /r/n only?
Please help me with my problem. THANK you in advance.