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

m (See Also)
m (Parameters: Link access levels)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{mirc title|On Sockread - Events}}
 
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.
 
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.
  
Line 7: Line 8:
  
 
== Parameters ==
 
== Parameters ==
<span style="display: inline-block; width: 105px;">'''<matchtext>'''</span>The name of the socket you want event to trigger on.
+
<span style="display: inline-block; width: 105px;"> '''<level>'''</span>The corresponding {{mIRC|access levels}} for the event to trigger.
 +
 
 +
<span style="display: inline-block; width: 105px;">'''<matchtext>'''</span>The name of the socket you want the event to trigger on.
  
 
<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.
Line 52: Line 55:
  
 
== See Also ==
 
== See Also ==
* [[mirc/on events|List of on events]]
+
* {{mirc|on events/on sockopen|on sockopen}}
* [[mirc/on events/on sockopen|on *:sockopen:]]
+
* {{mirc|on events/on sockwrite|on sockwrite}}
* [[mirc/on events/on sockwrite| on *:sockwrite:]]
+
* {{mirc|on events/on socklisten|on socklisten}}
* [[mirc/on events/on sockclose|on *:sockclose:]]
+
* {{mirc|on events/on sockclose|on sockclose}}
 
* {{mIRC|/sockopen}}
 
* {{mIRC|/sockopen}}
 
* {{mIRC|/sockwrite}}
 
* {{mIRC|/sockwrite}}

Latest revision as of 07:13, 6 February 2024

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.

Synopsis[edit]

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

Parameters[edit]

<level>The corresponding access levels for the event to trigger.

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

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

Connection State[edit]

It's important to check the value of $sockerr to determine if any connection errors occurred and handle that case. Here is a list of possible values returned by $sockerr in the on SOCKREAD event:

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

Examples[edit]

You can find more information and examples in the /sockread command page.

Here is a basic outline:

on *:sockread:example:{
 
  ;if an error occurred ($sockerr is not 0)
  if ($sockerr) {
    echo -s An error occurred: $sock($sockname).wsmsg
  }
 
  ;no error occurred ($sockerr was 0)
  else {
 
    ;perform commands related to reading the data
 
    ;declare %r as a local variable for use in /sockread
    var %r
 
    ;read a line into %r from the buffer (this variable is subject to mIRC's Line Length Limit - see the /sockread page for more information)
    sockread %r
 
    ;do things with %r, such as checking its value or extracting parts to output later
 
  }
}

Compatibility[edit]

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[edit]