Project

General

Profile

Sockudp » History » Revision 3

Revision 2 (Per Amundsen, 06/26/2017 03:06 PM) → Revision 3/4 (Per Amundsen, 12/23/2021 05:49 AM)

_Added in 2.3_ 

 */sockudp [-bntkdu] [-bntkd] [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":https://docs.microsoft.com/en-us/windows/win32/winsock/dual-stack-sockets. 

 *Parameters* 

 [bindip] - Bind ip to be used. 
 &lt;name&gt; - 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* 

 <pre> 
 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 
 } 
 </pre>