From WikiChip
mirc/commands/sockread
< mirc‎ | commands
Revision as of 20:33, 29 June 2014 by Zmodem (talk | contribs) (Created /sockread command - mIRC)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The /sockread command reads bytes from the receive buffer into a specified variable.

Synopsis

/sockread [-fn] [numbytes] <%var|&binvar>

Switches

Switch Description
f Forces mIRC to fill the variable with whatever text is in the receive buffer, even if it does not end in a $crlf.
n Reads 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.

Parameters

Parameter Description
[numbytes] The number of bytes to read from the receive buffer.
[%var/&binvar] The name of the variable to read the socket buffer into.

Example

When a socket connection, mySocket, has info waiting to be read from the buffer, store the info into a %myVar variable and echo it to a custom @myBuffer window:

ON 1:SOCKREAD:mySocket:{
  var %myVar
 
  ; Check for any socket errors; if they exist exit out of the event
  if ($sockerr > 0) { return }
 
  ; Create our jump loop for reading the socket buffer
  :nextread
 
  ; Read the buffer into the %myVar variable
  sockread %myVar
 
  ; Make sure that there is no socket break; if so exist out of the event
  if ($sockbr == 0) { return }
 
  ; If the buffer was empty, set the variable to printable empty space
  if (%myVar == $null) { %myVar = $chr(160) }
 
  ; Make sure our @myBuffer window is open; if not, create it
  if (!$window(@myBuffer)) { window @myBuffer }
 
  ; Echo the contents of the buffer variable into the @myBuffer window
  echo @myBuffer %myVar
 
  ; Go to the jump loop and read the rest of the buffer
  goto nextread
}

Compatibility

Added: mIRC v5.3

Added On: 13/12/97

See Also