$sockerr » History » Version 1
Per Amundsen, 08/12/2015 06:22 PM
1 | 1 | Per Amundsen | _Added in 1.9.0_ |
---|---|---|---|
2 | |||
3 | *$sockerr* |
||
4 | |||
5 | Returns any error during a socket command or socket [[Scripting_Events|event]]. |
||
6 | |||
7 | *Example* |
||
8 | |||
9 | <pre> |
||
10 | ; Open a socket connection to 'google.com' port '80'. |
||
11 | alias Example { |
||
12 | /sockopen Example www.google.com 80 |
||
13 | |||
14 | ; Check if there was an error. |
||
15 | if ($sockerr) { |
||
16 | echo -ag There was an error: $sockerr |
||
17 | } |
||
18 | } |
||
19 | |||
20 | ; Listen for the on SOCKOPEN event. |
||
21 | on *:SOCKOPEN:Example:{ |
||
22 | ; Write a GET request. |
||
23 | sockwrite -nt $sockname GET / HTTP/1.0 |
||
24 | sockwrite -n $sockname |
||
25 | |||
26 | ; Check if there was an error. |
||
27 | if ($sockerr) { |
||
28 | echo -ag There was an error: $sockerr |
||
29 | } |
||
30 | } |
||
31 | |||
32 | ; Listen for the on SOCKREAD event. |
||
33 | on *:SOCKREAD:Example:{ |
||
34 | ; Check if there was an error. |
||
35 | if ($sockerr) { |
||
36 | echo -ag There was an error: $sockerr |
||
37 | } |
||
38 | |||
39 | ; Create a local variable to hold the data. |
||
40 | var %i |
||
41 | |||
42 | ; Read the data waiting into the local variable. |
||
43 | sockread %i |
||
44 | |||
45 | ; Print data read. |
||
46 | echo -ag Data = %i |
||
47 | } |
||
48 | </pre> |