Project

General

Profile

$sockerr » History » Version 2

Per Amundsen, 08/12/2015 06:23 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 2 Per Amundsen
    halt
18 1 Per Amundsen
  }
19
}
20
21
; Listen for the on SOCKOPEN event.
22
on *:SOCKOPEN:Example:{
23
  ; Write a GET request.
24
  sockwrite -nt $sockname GET / HTTP/1.0 
25
  sockwrite -n $sockname
26
27
  ; Check if there was an error.
28
  if ($sockerr) {
29
    echo -ag There was an error: $sockerr
30 2 Per Amundsen
    halt
31 1 Per Amundsen
  }
32
}
33
34
; Listen for the on SOCKREAD event.
35
on *:SOCKREAD:Example:{
36
  ; Check if there was an error.
37
  if ($sockerr) {
38
    echo -ag There was an error: $sockerr
39 2 Per Amundsen
    halt
40 1 Per Amundsen
  }
41
42
  ; Create a local variable to hold the data.
43
  var %i
44
   
45
  ; Read the data waiting into the local variable.
46
  sockread %i
47
48
  ; Print data read.
49
  echo -ag Data = %i
50
}
51
</pre>