From WikiChip
Difference between revisions of "mirc/on events/on sockread"
< mirc‎ | on events

Line 1: Line 1:
The '''ON SOCKREAD''' triggers when there is info waiting to be read on the specified socket connection. You can read this info using the {{mIRC|/sockread}} command.
+
The '''ON SOCKREAD''' triggers when there is info waiting to be read on the specified TCP socket connection. You can read this info using the {{mIRC|/sockread}} command.
  
 
'''Note''': If this event triggers but no /sockread is performed to attempt to read the buffer, it is assumed that no script exists that is handling this buffer, so it is cleared and the info it contained is lost.
 
'''Note''': If this event triggers but no /sockread is performed to attempt to read the buffer, it is assumed that no script exists that is handling this buffer, so it is cleared and the info it contained is lost.
  
mIRC in general only understand $crlf terminated line. With socket, mIRC only understands $lf terminated line (any $cr before a $lf is removed).  
+
mIRC in general only understand $crlf terminated line. With socket, mIRC will stop at {{mIRC|$lf}} terminated line and any {{mIRC|$cr}} before a $lf is removed.
  
 
== Synopsis ==
 
== Synopsis ==
Line 12: Line 12:
  
 
<span style="display: inline-block; width: 105px;">'''<commands>'''</span>The commands to be performed when the event listener's criteria is met.
 
<span style="display: inline-block; width: 105px;">'''<commands>'''</span>The commands to be performed when the event listener's criteria is met.
 +
 +
== Connection State ==
  
 
You should be checking for $sockerr before reading data, here is a list of the possible value for $sockerr in the on SOCKREAD event:
 
You should be checking for $sockerr before reading data, here is a list of the possible value for $sockerr in the on SOCKREAD event:

Revision as of 19:36, 26 July 2014

The ON SOCKREAD triggers when there is info waiting to be read on the specified TCP socket connection. You can read this info using the /sockread command.

Note: If this event triggers but no /sockread is performed to attempt to read the buffer, it is assumed that no script exists that is handling this buffer, so it is cleared and the info it contained is lost.

mIRC in general only understand $crlf terminated line. With socket, mIRC will stop at $lf terminated line and any $cr before a $lf is removed.

Synopsis

ON <level>:SOCKREAD:<matchtext>:<commands>

Parameters

<matchtext>The name of the socket you want event to trigger on.

<commands>The commands to be performed when the event listener's criteria is met.

Connection State

You should be checking for $sockerr before reading data, here is a list of the possible value for $sockerr in the on SOCKREAD event:

  • 0 - Data received correctly.
  • 3 - Error on connected socket occurred, $sock().wsmsg will contain a more specific error message.

Examples

on *:sockread:name:{
  if ($sockerr) { echo -s An error occured while trying to read data: $sock($sockname).wsmsg | return }
  else {
    sockread %a
    echo -s rcvd: %a
  }
}

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 does not 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 terminated line in the buffer waiting to be read.

You can find an example showing how to do that here

Compatibility

Added: mIRC v3.5
Added on: 07 Aug 1995
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See Also