Difference between revisions of "Sockread"
m |
m |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
If you specify a %var variable, a line of text ending with a Carriage Return/LineFeed is read into %var. The $crlf are stripped off (this may result in %var being $null if the line only consisted of $crlf). | If you specify a %var variable, a line of text ending with a Carriage Return/LineFeed is read into %var. The $crlf are stripped off (this may result in %var being $null if the line only consisted of $crlf). | ||
− | If you specify a | + | If you specify the -f switch with a %var variable, this forces mIRC to fill the %var variable with whatever text is in the receive buffer, even if it doesn't end in a $crlf. |
− | If you specify the | + | If you specify a &binvar then [numbytes] of info is read into the binary variable. If no [numbytes] is specified it defaults to 4096 bytes. The &binvar is unset before filling it with the read data. |
The -n switch allows you to read a $crlf terminated line into a &binvar. If the incoming line does not contain a $crlf, no bytes will be read into &binvar, unless you specify the -f switch, which forces the read (same as when reading into %vars). | The -n switch allows you to read a $crlf terminated line into a &binvar. If the incoming line does not contain a $crlf, no bytes will be read into &binvar, unless you specify the -f switch, which forces the read (same as when reading into %vars). | ||
Line 16: | Line 16: | ||
Example: | Example: | ||
− | This example shows you how you should process a sockread event. The socket has already been opened and has received information, so the sockread event is triggered. The socket name is testing | + | This example shows you how you should process a sockread event. The socket has already been opened and has received information, so the sockread event is triggered. The socket name is testing. |
on 1:sockread:testing:{ | on 1:sockread:testing:{ | ||
− | + | ;when a sockerror occured, return | |
− | + | if ($sockerr > 0) return | |
− | + | ;start the loop to be able to sockread multiple times | |
− | + | while (1) { | |
− | + | sockread %temp | |
− | + | ;when nothing is read, the buffer was empty, so we return | |
− | + | if ($sockbr == 0) return | |
+ | echo -ag sockread: %temp | ||
+ | } | ||
} | } | ||
− | + | == See also == | |
* [[on sockread]] | * [[on sockread]] | ||
[[Category:Socket]] | [[Category:Socket]] | ||
+ | [[Category:Commands]] |
Latest revision as of 19:26, 30 January 2011
/sockread [-fn] [numbytes] <%var|&binvar>
The /sockread command reads bytes from the receive buffer into the specified variable.
If you specify a %var variable, a line of text ending with a Carriage Return/LineFeed is read into %var. The $crlf are stripped off (this may result in %var being $null if the line only consisted of $crlf).
If you specify the -f switch with a %var variable, this forces mIRC to fill the %var variable with whatever text is in the receive buffer, even if it doesn't end in a $crlf.
If you specify a &binvar then [numbytes] of info is read into the binary variable. If no [numbytes] is specified it defaults to 4096 bytes. The &binvar is unset before filling it with the read data.
The -n switch allows you to read a $crlf terminated line into a &binvar. If the incoming line does not contain a $crlf, no bytes will be read into &binvar, unless you specify the -f switch, which forces the read (same as when reading into %vars).
Note: A single /sockread may not be enough to read the entire buffer. You should keep reading until $sockbr (bytes read) is set to zero. This is far faster than letting mIRC re-trigger the event. If your script doesn't read the whole buffer, the on sockread event is re-triggered if: a) you were reading into a &binvar. b) you were reading into a %var and there is still a $crlf terminated line in the buffer waiting to be read.
Example: This example shows you how you should process a sockread event. The socket has already been opened and has received information, so the sockread event is triggered. The socket name is testing.
on 1:sockread:testing:{ ;when a sockerror occured, return if ($sockerr > 0) return ;start the loop to be able to sockread multiple times while (1) { sockread %temp ;when nothing is read, the buffer was empty, so we return if ($sockbr == 0) return echo -ag sockread: %temp } }