A single /sockread does not read the entire server response into the variable. Usually you read line by line, and in addition to the content of the request there are also headers. You're messaging '2' because the first line of the response does -not- contain 'self', and then you close the socket before reading the rest of the lines. To read the whole thing you should use a while loop like
while ($sockbr). Also note the request header changes, HTTP/1.1 to HTTP/1.0 to disable chunked transfer encoding (which can screw you up if you aren't writing code to support it) and the addition of the connection header so that twitch will close the connection automatically when the transfer is complete.
on *:text:!test:#: {
if ($sock(twitch)) .sockclose twitch
sockopen -e twitch api.twitch.tv 443
}
on *:SOCKOPEN:twitch: {
sockwrite -nt $sockname GET /kraken/streams/tehpolecat HTTP/1.0
sockwrite -nt $sockname Host: api.twitch.tv
sockwrite -nt $sockname Connection: close
sockwrite $sockname $crlf
}
on *:SOCKREAD:twitch: {
if ($sockerr) return
var %sockreader
sockread %sockreader
while ($sockbr) {
if (%sockreader) echo -ag %sockreader
sockread %sockreader
}
}
Use [code] to wrap code instead of [quote]