(→Accepting a connection) |
m (→Compatibility: This was added in 5.3) |
||
(19 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | The '''ON SOCKLISTEN''' event triggers when a connection is made on a listening socket created with {{mIRC|/socklisten}} | + | {{mirc title|On Socklisten - Events}} |
+ | The '''ON SOCKLISTEN''' event triggers when a connection is made on a listening {{mIRC|sockets#mIRC sockets|TCP socket}} created with {{mIRC|/socklisten}} | ||
== Synopsis == | == Synopsis == | ||
Line 5: | Line 6: | ||
== 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 event to trigger on. | ||
Line 11: | Line 14: | ||
== Accepting a connection == | == Accepting a connection == | ||
− | '''Note''': By design, you cannot prevent a socket from being accepted, as in, Windows | + | '''Note''': By design, you cannot prevent a socket from being accepted, as in, Windows accepts the connection even before mIRC. |
You can use /sockaccept <newsocket> to accept a socket, mIRC create the new socket. | You can use /sockaccept <newsocket> to accept a socket, mIRC create the new socket. | ||
− | '''Note''': If a new connection occurs on a socket but there is no on socklisten event matching that socket, the connection is rejected. | + | '''Note''': If a new connection occurs on a listening socket but there is no on socklisten event matching that socket, the connection is rejected. |
+ | |||
+ | You should be checking for $sockerr before accepting the connection to see if an error occured, here is a list of the possible value for $sockerr in the on SOCKLISTEN event: | ||
− | '''Note''' | + | * '''0''' - New socket successfuly accepted. |
+ | * '''1''' - Error occurred on listening socket, $sock().wsmsg will contain a more specific error message. Note that getting this error is considered rare. | ||
+ | * '''2''' - Error accepting new socket, $sock().wsmsg will contain a more specific error message. | ||
+ | * '''4''' - Not enough memory for new socket. Note that getting this error is considered rare. | ||
== Examples == | == Examples == | ||
Line 23: | Line 31: | ||
<source lang="mirc"> | <source lang="mirc"> | ||
on *:socklisten:name:{ | on *:socklisten:name:{ | ||
− | sockaccept myprefix $+ $ticks | + | if (!$sockerr) sockaccept myprefix $+ $ticks |
+ | else { | ||
+ | echo -s An error occured while trying to accept a connection: $sock($sockname).wsmsg | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
== Compatibility == | == Compatibility == | ||
− | {{mIRC compatibility|3 | + | {{mIRC compatibility|5.3}} |
== See Also == | == See Also == | ||
− | * {{mIRC| | + | * {{mIRC|on events|mIRC events}} |
+ | * {{mirc|on events/on sockopen|on sockopen}} | ||
+ | * {{mirc|on events/on sockread|on sockread}} | ||
+ | * {{mirc|on events/on sockwrite|on sockwrite}} | ||
+ | * {{mirc|on events/on sockclose|on sockclose}} | ||
* {{mIRC|/sockwrite}} | * {{mIRC|/sockwrite}} | ||
* {{mIRC|/sockclose}} | * {{mIRC|/sockclose}} | ||
Line 39: | Line 54: | ||
* {{mIRC|$sock}} | * {{mIRC|$sock}} | ||
* {{mIRC|$sockbr}} | * {{mIRC|$sockbr}} | ||
− | * {{mIRC| | + | * {{mIRC|$sockerr}} |
− | [[Category: | + | [[Category:mIRC on events|socklisten]] |
Latest revision as of 10:39, 18 February 2024
The ON SOCKLISTEN event triggers when a connection is made on a listening TCP socket created with /socklisten
Synopsis[edit]
ON <level>:SOCKLISTEN:<matchtext>:<commands>
Parameters[edit]
<level>The corresponding access levels for the event to trigger.
<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.
Accepting a connection[edit]
Note: By design, you cannot prevent a socket from being accepted, as in, Windows accepts the connection even before mIRC.
You can use /sockaccept <newsocket> to accept a socket, mIRC create the new socket.
Note: If a new connection occurs on a listening socket but there is no on socklisten event matching that socket, the connection is rejected.
You should be checking for $sockerr before accepting the connection to see if an error occured, here is a list of the possible value for $sockerr in the on SOCKLISTEN event:
- 0 - New socket successfuly accepted.
- 1 - Error occurred on listening socket, $sock().wsmsg will contain a more specific error message. Note that getting this error is considered rare.
- 2 - Error accepting new socket, $sock().wsmsg will contain a more specific error message.
- 4 - Not enough memory for new socket. Note that getting this error is considered rare.
Examples[edit]
on *:socklisten:name:{ if (!$sockerr) sockaccept myprefix $+ $ticks else { echo -s An error occured while trying to accept a connection: $sock($sockname).wsmsg } }
Compatibility[edit]
Added: mIRC v5.3
Added on: 13 Dec 1997
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.