on *:sockread:YOURSOCKET:{
handle any socket errors that have occured
if ($sockerr) {
echo -s SOCKET READ Error: $sockname : $sock($sockname).wsmsg
return
}
;setup a loop so we will be able to read all data in the rcvdQ
:loop
;read from socket
sockread &tmp
;if no data was read, top processing
if (!$sockbr) { return }
;setup 3 variables to be used as we track down the "packet length"s, and find the first instance of $crlf
var %a, %b, %x = $bfind(&tmp, 1, $crlf)
;loop through finding each instance of crlf
while ($bfind(&tmp,$calc(%x +1),$crlf)) {
;set %a to the length between $crlf's found
%a = $calc($v1 +2 - %x)
;if the length between crlf's found is between 5 and 8 bytes, and the data between matches hexidecimal codings
if (%a isnum 5-8 && $regex($bvar(&tmp,%x,%a).text,/^\r\n[a-f0-9]+$/i)) {
;if \r\n0\r\n matches the data between crlfs, then set %b to true, signfying the whole page is read
if ($bvar(&tmp,%x,%a).text = $crlf $+ 0 $+ $crlf) { %b = $true }
;copy the bytes after the 2nd crlf found, to the position of the first crlf(deleting the \r\nBytes\r\n)
bcopy -c &tmp %x &tmp $calc(%x + %a +2) -1
;find the next crlf and set %x to it's position
%x = $bfind(&tmp,%x,$crlf)
}
;if the data wasn't what we were looking for, set the search location to right after the 2nd found crlf's position
else { %x = $calc(%a + %x) }
}
;do stuff with &tmp now that all \r\nBYTES\r\n has been removed
;if we haven't found the end of the page yet, go back and read again
if (!%b) { goto loop }
;now that that whole page is read, do stuff after reading
}