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

(Example)
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The '''/sockudp command''' allows you to send data to a specific address at a specific port destination. Check out the UDP article [[UDP Sockets - mIRC|here]]
+
{{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().wserr to the error value, and trigger on sockwrite with $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 ==
Line 8: Line 9:
 
== Switches ==
 
== Switches ==
 
* '''-b''' - Indicates that you are specifying the numbytes value which is the number of bytes you want send, the full line is sent otherwise
 
* '''-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
+
* '''-n''' - Appens a {{mIRC|$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
 
* '''-t''' - Forces mIRC to send anything beginning with a & as plain text
 
* '''-k''' - Keeps the socket opened
 
* '''-k''' - Keeps the socket opened
Line 20: Line 21:
 
* '''<port>''' - The port you want to send to information to, that's your listening port if you create a server.
 
* '''<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.
 
* '''[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 ==
 
== 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
 +
}
  
== Compatibility ==
+
ON *:UDPREAD:gettime: {
Added: mIRC v5.5
+
  ; 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)
  
Added On: 08/01/99
+
  ; 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>
  
<small>Note: Individual switches were not taken into consideration.</small>
+
== Compatibility ==
 +
{{mIRC compatibility|5.5}}
  
 
== See also ==
 
== See also ==
Line 38: Line 62:
 
* [[on sockwrite - mIRC|on sockwrite]]
 
* [[on sockwrite - mIRC|on sockwrite]]
 
* [[$sockerr - Identifiers |$sockerr]]
 
* [[$sockerr - Identifiers |$sockerr]]
 +
{{mIRC command list}}
  
[[Category:mIRC commands]]
+
[[Category:mIRC commands|sockudp command - mIRC]]

Revision as of 16:31, 28 January 2021

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

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

Switches

  • -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

Parameters

  • [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

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

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

v · d · e mIRC commands list

A /abook, /action, /add, /ajinvite, /alias, /aline, /ame, /amsg, /anick, /aop, /auser, /auto, /autojoin, /avoice, /away

B /background, /ban, /bcopy, /beep, /bindip, /bread, /break, /breplace, /bset, /btrunc, /bunset, /bwrite

C /channel, /clear, /clearall, /clearial, /cline, /clipboard, /close, /closechats, /closedccs, /closefserves, /closemsg, /cnick, /color, /colour, /comclose, /comlist, /commands, /comopen, /comreg, /continue, /copy, /creq, /ctcp, /ctcpreply, /ctcps

D /dcc, /dccserver, /dde, /ddeserver, /debug, /dec, /describe, /dialog, /did, /didtok, /disable, /disconnect, /dlevel, /dline, /dll, Template:mIRC/donotdisturb, /dns, /dqwindow, /drawcopy, /drawdot, /drawfill, /drawline, /drawpic, /drawrect, /drawreplace, /drawrot, /drawsave, /drawscroll, /drawsize /drawtext

E /ebeeps, /echo, /editbox, /else, /elseif, /emailaddr, /enable, /events, /exit

F /fclose, /filter, /findtext, /finger, /firewall, /flash, /flist, /flood, /flush, /flushini, /fnord, /font, /fopen, /fseek, /fsend, /fserve, /fullname, /fupdate, /fwrite

G /ghide, /gload, /gmove, /gopts, /goto, /gplay, /gpoint, /gqreq, /groups, /gshow, /gsize, /gstop, /gtalk, /gunload, /guser

H /hadd, /halt, /haltdef, /hdec, /hdel, /help, /hfree, /hinc, /hload, /hmake, /hotlink, /hop, /hsave

I /ial, /ialclear, /ialmark, /identd, /if, /ignore, /iline, /inc, /iuser

J /join

L /leave, /linesep, /links, /list, /load, /loadbuf, /localinfo, /log, /logview

M /maxdepth, /mdi, /me, /menubar, /mkdir, /mnick, /mode, /msg

N /noop, /notice, /notify

O /onotice, /omsg

P /pareline, /part, /partall, /pdcc, /perform, /play, /playctrl, /pop, /protect, /proxy, /pvoice

Q /qme, /qmsg, /query, /queryrn, /quit, /quote

R /raw, /registration, /reload, /remini, /remote, /remove, /rename, /renwin, /reseterror, /resetidle, /return, /returnex, /rlevel, /rline, /rmdir, /run, /ruser

S /save, /savebuf, /saveini, /say, /scid, /scon, /server, /set, /setlayer, /showmirc, /signal, /sline, /sockaccept, /sockclose, /socklist, /socklisten, /sockmark, /sockopen, /sockpause, /sockread, /sockrename, /sockudp, /sockwrite, /sound, /speak, /splay, /sreq, /strip, /switchbar

T /timer, /timestamp, /tip, /tips, /titlebar, /tnick, /tokenize, /toolbar, /topic /tray, /treebar

U /ulist, /unload, /unset, /unsetall, /updatenl, /url, /username, /uwho

V /var, /vcadd, /vcmd, /vcrem, /vol

W

X /xyzzy