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

(Created page with "The '''ON SOCKOPEN''' event triggers when a socket connection initiated with {{mIRC|/sockopen} is either sucessful or failed. == Synopsis == <pre>ON <level>:SOCKOPEN:<matcht...")
 
m (Parameters: Correct typo)
 
(24 intermediate revisions by 6 users not shown)
Line 1: Line 1:
The '''ON SOCKOPEN''' event triggers when a socket connection initiated with {{mIRC|/sockopen} is either sucessful or failed.  
+
{{mirc title|On Sockopen - Events}}
 +
The '''ON SOCKOPEN''' event triggers when a TCP socket connection initiated with {{mIRC|/sockopen}} is either successfull or failed. This event also trigger after an SSL negociation (STARTTLS feature) is finished, you can check $sock().starttls which will be set to $true if the negociation was successful.
  
 
== Synopsis ==
 
== Synopsis ==
Line 5: Line 6:
  
 
== 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.
  
You should be checking {{mIRC|$sockerr}} to know if the connection was sucessful or not, here is a list of the possible value for $sockerr in the on SOCKOPEN event:
+
== Connection State ==
 +
 
 +
Because the sockopen event triggers for failed connections as well as successful connections, it's important to check the value of {{mIRC|$sockerr}} before continuing with any commands. Here is a list of the possible values returned by $sockerr in the on SOCKOPEN event:
  
 
* '''0''' - Success.
 
* '''0''' - Success.
* '''3''' - Failure establishing socket connection, $sock().wsmsg will contain a more specific error message.
+
* '''3''' - Failure establishing socket connection: $sock($sockname).wsmsg will contain a more specific error message.
 
* '''4''' - Error resolving given hostname.
 
* '''4''' - Error resolving given hostname.
 
  
 
== Examples ==
 
== Examples ==
  
 
<source lang="mirc">
 
<source lang="mirc">
on *:socklisten:name:{
+
on *:sockopen:example:{
   if (!$sockerr) sockaccept myprefix $+ $ticks
+
 
 +
  ;if an error occurred ($sockerr is not 0)
 +
   if ($sockerr) {
 +
    if ($sockerr == 3) {
 +
      echo -s An error occurred while trying to connect: $sock($sockname).wsmsg
 +
    }
 +
    elseif ($sockerr == 4) {
 +
      echo -s Error resolving hostname
 +
    }
 +
  }
 +
 
 +
  ;no error occurred ($sockerr was 0)
 
   else {
 
   else {
     echo -s An error occured while trying to accept a connection: $sock($sockname).wsmsg
+
     ;perform commands after establishing a connection.
 +
    ;usually this involves making a request for a webpage as shown below:
 +
    sockwrite -n $sockname GET / HTTP/1.1
 +
    sockwrite -n $sockname Host: www.example.com
 +
    sockwrite -n $sockname Connection: close
 +
    sockwrite    $sockname $crlf
 
   }
 
   }
 
}
 
}
Line 31: Line 51:
  
 
== See Also ==
 
== See Also ==
* {{mIRC|List of on events|mIRC events}}
+
* {{mirc|on events/on sockread|on sockread}}
 +
* {{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|/sockread}}
 
* {{mIRC|/sockclose}}
 
* {{mIRC|/sockclose}}
* {{mIRC|/sockread}}
 
 
* {{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]]
+
[[Category:mIRC on events|sockopen]]

Latest revision as of 07:12, 6 February 2024

The ON SOCKOPEN event triggers when a TCP socket connection initiated with /sockopen is either successfull or failed. This event also trigger after an SSL negociation (STARTTLS feature) is finished, you can check $sock().starttls which will be set to $true if the negociation was successful.

Synopsis[edit]

ON <level>:SOCKOPEN:<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]

Because the sockopen event triggers for failed connections as well as successful connections, it's important to check the value of $sockerr before continuing with any commands. Here is a list of the possible values returned by $sockerr in the on SOCKOPEN event:

  • 0 - Success.
  • 3 - Failure establishing socket connection: $sock($sockname).wsmsg will contain a more specific error message.
  • 4 - Error resolving given hostname.

Examples[edit]

on *:sockopen:example:{
 
  ;if an error occurred ($sockerr is not 0)
  if ($sockerr) {
    if ($sockerr == 3) {
      echo -s An error occurred while trying to connect: $sock($sockname).wsmsg
    }
    elseif ($sockerr == 4) {
      echo -s Error resolving hostname
    }
  }
 
  ;no error occurred ($sockerr was 0)
  else {
    ;perform commands after establishing a connection.
    ;usually this involves making a request for a webpage as shown below:
    sockwrite -n $sockname GET / HTTP/1.1
    sockwrite -n $sockname Host: www.example.com
    sockwrite -n $sockname Connection: close
    sockwrite    $sockname $crlf
  }
}

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]