Project

General

Profile

Actions

Sockudp » History » Revision 3

« Previous | Revision 3/4 (diff) | Next »
Per Amundsen, 12/23/2021 05:49 AM


Added in 2.3

/sockudp [-bntkdu] [bindip] <name> [port] <ipaddress> <port> [numbytes] [text|%var|&binvar]

Opens a UDP connection to a remote ipaddress/port and sends a UDP packet.

Switches

-b - Indicates that you are specifying the numbytes value which is the number of bytes you want sent.
-n - Appends a $crlf to the line being sent if it is not a &binvar and if it does not already have a $crlf.
-t - Forces AdiIRC to send anything beginning with a & as normal text instead of interpreting it as a binary variable.
-k - Forces the socket to stay open, so it can receive UDP data.
-d - The specified IP address is the bind ip address.
-u - Enables dual stack sockets.

Parameters

[bindip] - Bind ip to be used.
<name> - Socket connection name.
[port] - Bind port to be used.
<ipaddress> - Remote ipaddress to connect to.
<port> - Remote port to connect to.
[numbytes] - Number of bytes to send. (used with -b)
[text|%var|&binvar] - Text, %variable or &binvar to send.

Example

alias gettime {
  ; Set a NULL byte binary variable.
  bset &null 1 0

  ; Open a UDP connection to Time-a.nist.gov = 129.6.15.28
  sockudp -k gettime 129.6.15.28 37 &null
}

on *:udpread:gettime: {

  ; Read the reply.
  sockread -f &time

  var %time $bvar(&time,1,$bvar(&time,0))

  ; Convert to binary, remove spaces.
  var %bin $regsubex(%time, /(\d+)\s?/g, $base(\1, 10, 2, 8))

  ; Get the current unix time in decimal system.
  var %time = $base(%bin, 2, 10)

  ; Print the time and close the socket.
  echo -ag Currnt Time/Date: $asctime($calc(%time - 2208988800), yyyy-mm-dd hh:nn:ss TT)
  sockclose $sockname
}

Updated by Per Amundsen about 3 years ago · 3 revisions

Also available in: PDF HTML TXT