From WikiChip
Editing mirc/on events/on sockread

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
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.
  
'''Note''': If this event triggers but no {{mIRC|/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 will stop at {{mIRC|$lf}} terminated line and any {{mIRC|$cr}} before a $lf is removed.
 +
 
 +
'''Note''': A single /sockread may not be enough to read the entire buffer. You should keep reading until {{mIRC|$sockbr}} 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 {{mIRC|/sockread#Example|here}}
  
 
== Synopsis ==
 
== Synopsis ==
Line 8: Line 16:
  
 
== Parameters ==
 
== Parameters ==
<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 event to trigger on.
 
 
<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 16: Line 22:
 
== Connection State ==
 
== Connection State ==
  
It's important to check the value of {{mIRC|$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:
+
You should be checking for error with $sockerr before reading data, here is a list of the possible value for $sockerr in the on SOCKREAD event:
  
 
* '''0''' - Data received correctly.
 
* '''0''' - Data received correctly.
* '''3''' - Error occurred on connected socket: $sock($sockname).wsmsg will contain a more specific error message.
+
* '''3''' - Error on connected socket occurred, $sock().wsmsg will contain a more specific error message.
  
 
== Examples ==
 
== Examples ==
  
You can find more information and examples in the {{mIRC|/sockread}} command page.
 
 
Here is a basic outline:
 
 
<source lang="mirc">
 
<source lang="mirc">
on *:sockread:example:{
+
on *:sockread:name:{
 
+
   if ($sockerr) { echo -s An error occured while trying to read data: $sock($sockname).wsmsg | return }
  ;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 {
 
   else {
 
+
     sockread %a
     ;perform commands related to reading the data
+
     echo -s rcvd: %a
 
 
    ;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
 
 
 
 
   }
 
   }
 
}
 
}
Line 55: Line 43:
  
 
== See Also ==
 
== See Also ==
* {{mirc|on events/on sockopen|on sockopen}}
+
* {{mIRC|List of on events|mIRC events}}
* {{mirc|on events/on sockwrite|on sockwrite}}
 
* {{mirc|on events/on socklisten|on socklisten}}
 
* {{mirc|on events/on sockclose|on sockclose}}
 
* {{mIRC|/sockopen}}
 
 
* {{mIRC|/sockwrite}}
 
* {{mIRC|/sockwrite}}
 +
* {{mIRC|/sockclose}}
 
* {{mIRC|/sockread}}
 
* {{mIRC|/sockread}}
* {{mIRC|/sockclose}}
 
 
* {{mIRC|/sockaccept}}
 
* {{mIRC|/sockaccept}}
 
* {{mIRC|/sockpause}}
 
* {{mIRC|/sockpause}}
* {{mIRC|$sockname}}
 
 
* {{mIRC|$sock}}
 
* {{mIRC|$sock}}
 
* {{mIRC|$sockbr}}
 
* {{mIRC|$sockbr}}
 
* {{mIRC|$sockerr}}
 
* {{mIRC|$sockerr}}
  
[[Category:mIRC on events|sockread]]
+
[[Category:MIRC on events]]

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)