Sockudp » History » Version 3
Per Amundsen, 12/23/2021 05:49 AM
1 | 1 | Per Amundsen | _Added in 2.3_ |
---|---|---|---|
2 | |||
3 | 3 | Per Amundsen | */sockudp [-bntkdu] [bindip] <name> [port] <ipaddress> <port> [numbytes] [text|%var|&binvar]* |
4 | 1 | Per Amundsen | |
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 | 3 | Per Amundsen | -u - Enables "dual stack sockets":https://docs.microsoft.com/en-us/windows/win32/winsock/dual-stack-sockets. |
15 | 1 | Per Amundsen | |
16 | *Parameters* |
||
17 | |||
18 | [bindip] - Bind ip to be used. |
||
19 | <name> - Socket connection name. |
||
20 | [port] - Bind port to be used. |
||
21 | <ipaddress> - Remote ipaddress to connect to. |
||
22 | <port> - Remote port to connect to. |
||
23 | [numbytes] - Number of bytes to send. (used with -b) |
||
24 | 2 | Per Amundsen | [text|%var|&binvar] - Text, %variable or &binvar to send. |
25 | |||
26 | *Example* |
||
27 | |||
28 | <pre> |
||
29 | alias gettime { |
||
30 | ; Set a NULL byte binary variable. |
||
31 | bset &null 1 0 |
||
32 | |||
33 | ; Open a UDP connection to Time-a.nist.gov = 129.6.15.28 |
||
34 | sockudp -k gettime 129.6.15.28 37 &null |
||
35 | } |
||
36 | |||
37 | on *:udpread:gettime: { |
||
38 | |||
39 | ; Read the reply. |
||
40 | sockread -f &time |
||
41 | |||
42 | var %time $bvar(&time,1,$bvar(&time,0)) |
||
43 | |||
44 | ; Convert to binary, remove spaces. |
||
45 | var %bin $regsubex(%time, /(\d+)\s?/g, $base(\1, 10, 2, 8)) |
||
46 | |||
47 | ; Get the current unix time in decimal system. |
||
48 | var %time = $base(%bin, 2, 10) |
||
49 | |||
50 | ; Print the time and close the socket. |
||
51 | echo -ag Currnt Time/Date: $asctime($calc(%time - 2208988800), yyyy-mm-dd hh:nn:ss TT) |
||
52 | sockclose $sockname |
||
53 | } |
||
54 | </pre> |