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