I think you're still not understanding what's happening, the sockread is putting the ENTIRE CONTENT pulled from the receive queue into the binvar INCLUDING the line break, $bvar(&var,0) and $sockbr are equal, what was removed from the recieve queue is represented in the binary variable it was moved to.
For your convenience, since you used -n, the CRLF is nullified, replaced, changed to termination character, There is no magical addition of 0's they're simply the result of a replacement. These didn't come from no-where.
Take this example, like you were processing characters one at a time and removing them:
alias example {
;-- Set up some binvar with some characters
bset -t &var 1 test
;-- Counter for as characters are removed, and placeholder of string remaining.
var %tot = 0 , %str = $bvar(&var,1-).text
echo -a Array Size: $bvar(&var,0) Array: $bvar(&var,1-) -=- String Size: $len(%str) String: $qt(%str)
;-- Remove 1st character until none remain
while ($bvar(&var,1-).text) {
bcopy -z &var 1 &var 2 -1
var %tot = %tot + 1 , %str = $bvar(&var,1-).text
echo -a %tot - Array Size: $bvar(&var,0) Array: $bvar(&var,1-) -=- String Size: $len(%str) String: $qt(%str)
}
}
Output:
Array Size: 4 Array: 116 101 115 116 -=- String Size: 4 String: "test"
1 - Array Size: 4 Array: 101 115 116 0 -=- String Size: 3 String: "est"
2 - Array Size: 4 Array: 115 116 0 0 -=- String Size: 2 String: "st"
3 - Array Size: 4 Array: 116 0 0 0 -=- String Size: 1 String: "t"
4 - Array Size: 4 Array: 0 0 0 0 -=- String Size: 0 String: ""
while the string itself keeps changing, the array size does not.