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

m
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{mIRC Guide}}
+
{{mirc title|On Udpread - Events}}The '''ON UDPREAD''' triggers when there is info waiting to be read on the specified UDP socket connection. You can read this info using the {{mIRC|/sockread}} command.
The '''ON UDPREAD''' triggers when there is info waiting to be read on the specified UDP socket connection. You can read this info using the {{mIRC|/sockread}} command.
 
  
 
To be able to use this event, you need to get the udp socket to stay opened (by default it is closed after each {{mIRC|/sockudp}} command) by using the -k switch of /sockudp.
 
To be able to use this event, you need to get the udp socket to stay opened (by default it is closed after each {{mIRC|/sockudp}} command) by using the -k switch of /sockudp.
  
'''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 will stop at {{mIRC|$lf}} terminated line and any {{mIRC|$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.
  
'''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 udpread event is re-triggered if:
+
'''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 udpread event is re-triggered if:
  
* a) you were reading into a &binvar.
+
# 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 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}}
 
You can find an example showing how to do that {{mIRC|/sockread#Example|here}}
Line 56: Line 55:
 
* {{mIRC|$sockerr}}
 
* {{mIRC|$sockerr}}
  
[[Category:mIRC on events|sockread]]
+
[[Category:mIRC on events|udpread]]

Revision as of 11:35, 21 September 2017

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

To be able to use this event, you need to get the udp socket to stay opened (by default it is closed after each /sockudp command) by using the -k switch of /sockudp.

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.

Note: A single /sockread may not be enough to read the entire buffer. You should keep reading until $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 udpread event is re-triggered if:

  1. you were reading into a &binvar.
  2. 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

Synopsis

ON <level>:UDPREAD:<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 error with $sockerr before reading data, here is a list of the possible value for $sockerr in the on UDPREAD event:

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

Examples

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

Compatibility

Added: mIRC v5.5
Added on: 08 Jan 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See Also