From WikiChip
Difference between revisions of "mirc/commands/sockudp"
< mirc‎ | commands

m (Bot: Fixing compatibility)
m (See Also: Fix links)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The '''/sockudp command''' allows you to send data to a specific address at a specific port destination (See [[UDP Sockets - mIRC|UDP sockets]]).
+
{{mirc title|/sockudp Command}}
 +
The '''/sockudp command''' allows you to send data to a specific address at a specific port destination (See {{mIRC|UDP sockets}}).
  
'''Note''': if /sockudp fails, it sets [[$sock identifier - mIRC|$sock().wserr]] to the error value, and trigger on sockwrite with {{mIRC|$sockerr}} set etc.
+
'''Note''': if /sockudp fails, it sets {{mIRC|$sock|$sock().wserr}} to the error value, and trigger on sockwrite with {{mIRC|$sockerr}} set etc.
  
 
== Synopsis ==
 
== Synopsis ==
/sockudp -bntkd [bindip] <name> [port] <ipaddress> <port> [numbytes] [text|%var|&binvar]
+
/sockudp -bntkduz [bindip] <name> [port] <ipaddress> <port> [numbytes] [text|%var|&binvar]
  
 
== Switches ==
 
== Switches ==
Line 12: Line 13:
 
* '''-k''' - Keeps the socket opened
 
* '''-k''' - Keeps the socket opened
 
* '''-d''' - Means you have specified the ip address as the bind address
 
* '''-d''' - Means you have specified the ip address as the bind address
 +
* '''-u''' - Enables dual stack socket to support both ipv4 and ipv6 for the listening socket, if that is available, you must bind to an ipv6 ip address
 +
* '''-z''' - Wait for the data to be sent if any and then close the socket
  
 
== Parameters ==
 
== Parameters ==
Line 23: Line 26:
  
 
== Example ==
 
== Example ==
 +
<source lang="mIRC">
 +
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.
 +
  echo -ag Currnt Time/Date: $asctime($calc(%time - 2208988800), yyyy-mm-dd hh:nn:ss TT)
 +
 +
  ; Close the socket
 +
  sockclose $sockname
 +
}
 +
</source>
  
 
== Compatibility ==
 
== Compatibility ==
Line 31: Line 61:
 
* [[List of commands - mIRC|List of commands]]
 
* [[List of commands - mIRC|List of commands]]
 
* [[List of identifiers - mIRC|List of identifiers]]
 
* [[List of identifiers - mIRC|List of identifiers]]
* [[on udpread - mIRC|on udpread]]
+
* {{mIRC|on udpread}}
* [[on sockwrite - mIRC|on sockwrite]]
+
* {{mIRC|on sockwrite}}
* [[$sockerr - Identifiers |$sockerr]]
+
* {{mIRC|$sockerr}}
 
{{mIRC command list}}
 
{{mIRC command list}}
  
[[Category:MIRC commands]]
+
[[Category:mIRC commands|sockudp command - mIRC]]

Latest revision as of 03:52, 9 February 2024

The /sockudp command allows you to send data to a specific address at a specific port destination (See UDP sockets).

Note: if /sockudp fails, it sets $sock().wserr to the error value, and trigger on sockwrite with $sockerr set etc.

Synopsis[edit]

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

Switches[edit]

  • -b - Indicates that you are specifying the numbytes value which is the number of bytes you want send, the full line is sent otherwise
  • -n - Appens a $crlf to the line being sent if it's not a &binvar or if does not already end with a $crlf
  • -t - Forces mIRC to send anything beginning with a & as plain text
  • -k - Keeps the socket opened
  • -d - Means you have specified the ip address as the bind address
  • -u - Enables dual stack socket to support both ipv4 and ipv6 for the listening socket, if that is available, you must bind to an ipv6 ip address
  • -z - Wait for the data to be sent if any and then close the socket

Parameters[edit]

  • [bindip] - If -d has been specified, the ip address you want to use as the bind address.
  • <name> - The sockname name.
  • [port] - If specified, the local port to use, otherwise mIRC choose one randomly.
  • <ipaddress> - The ip address you want to send to information to, use you localhost 127.0.0.1 with -k to create a listening socket.
  • <port> - The port you want to send to information to, that's your listening port if you create a server.
  • [numbytes] - If -b has been specified, indicates the number of bytes you want to send.
  • [text|%var|&binvar] - If specified, the message you want to send, can be a binary variable. You don't want to specify that parameter if you create a server.

Example[edit]

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.
  echo -ag Currnt Time/Date: $asctime($calc(%time - 2208988800), yyyy-mm-dd hh:nn:ss TT)
 
  ; Close the socket
  sockclose $sockname
}

Compatibility[edit]

Added: mIRC v5.5
Added on: 08 Jan 1999
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See also[edit]

[Expand]
v · d · e mIRC commands list