From WikiChip
Difference between revisions of "mirc/on events/on sockopen"
(→See Also) |
Yawhatnever (talk | contribs) m (→Showing the $crlf being written on the last line is clearer. a comment explaining it would be overkill; this isn't a tutorial for the HTTP protocol) |
||
Line 39: | Line 39: | ||
sockwrite -n $sockname Host: www.example.com | sockwrite -n $sockname Host: www.example.com | ||
sockwrite -n $sockname Connection: close | sockwrite -n $sockname Connection: close | ||
− | sockwrite | + | sockwrite $sockname $crlf |
} | } | ||
} | } |
Revision as of 15:05, 16 October 2014
The ON SOCKOPEN event triggers when a TCP socket connection initiated with /sockopen is either successfull or failed.
Synopsis
ON <level>:SOCKOPEN:<matchtext>:<commands>
Parameters
<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
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
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
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.