Project

General

Profile

Sockudp » History » Version 2

Per Amundsen, 06/26/2017 03:06 PM

1 1 Per Amundsen
_Added in 2.3_
2
3
*/sockudp [-bntkd] [bindip] <name> [port] <ipaddress> <port> [numbytes] [text|%var|&binvar]*
4
5
Opens a UDP connection to a remote ipaddress/port and sends a UDP packet.
6
7
*Switches*
8
9
-b - Indicates that you are specifying the numbytes value which is the number of bytes you want sent.
10
-n - Appends a [[$crlf]] to the line being sent if it is not a &binvar and if it does not already have a [[$crlf]].
11
-t - Forces AdiIRC to send anything beginning with a *&* as normal text instead of interpreting it as a binary variable.
12
-k - Forces the socket to stay open, so it can receive UDP data.
13
-d - The specified IP address is the bind ip address.
14
15
*Parameters*
16
17
[bindip] - Bind ip to be used.
18
&lt;name&gt; - Socket connection name.
19
[port] - Bind port to be used.
20
<ipaddress> - Remote ipaddress to connect to.
21
<port> - Remote port to connect to.
22
[numbytes] - Number of bytes to send. (used with -b)
23 2 Per Amundsen
[text|%var|&binvar] - Text, %variable or &binvar to send.
24
25
*Example*
26
27
<pre>
28
alias gettime {
29
  ; Set a NULL byte binary variable.
30
  bset &null 1 0
31
32
  ; Open a UDP connection to Time-a.nist.gov = 129.6.15.28
33
  sockudp -k gettime 129.6.15.28 37 &null
34
}
35
36
on *:udpread:gettime: {
37
38
  ; Read the reply.
39
  sockread -f &time
40
41
  var %time $bvar(&time,1,$bvar(&time,0))
42
 
43
  ; Convert to binary, remove spaces.
44
  var %bin $regsubex(%time, /(\d+)\s?/g, $base(\1, 10, 2, 8))
45
 
46
  ; Get the current unix time in decimal system.
47
  var %time = $base(%bin, 2, 10)
48
 
49
  ; Print the time and close the socket.
50
  echo -ag Currnt Time/Date: $asctime($calc(%time - 2208988800), yyyy-mm-dd hh:nn:ss TT)
51
  sockclose $sockname
52
}
53
</pre>