Sockudp

From Scriptwiki
Jump to: navigation, search

SockUDP is the command used to send UDP packets to a destination host. In this, it is like the TCP sockwrite command.

SockUDP however is also used to begin listening for UDP packets on a specified local port. In this, it is like the TCP sockopen command.

sockudp [-bntkd] [bindip] <name> [localport] [ipaddress remoteport] [numbytes] [text|%var|&binvar]
  • Switches
    • -b means you are specifying the number of bytes to send. If you specify a number of bytes (numbytes) the data will be truncated to this length.
    • -n will append $crlf to the end of the packet. For most protocols, you should not use this! Appending two extra bytes may not work with the protocol you are using.
    • -t means you are sending text (in literal or %var form). In other words, &binvars are not evaluated as binary variables.
    • -k means you wish for this socket to remain open on localport to listen for incoming UDP data.
    • -d is used when a bindip is being specified. If you use this, you must specify a bindip and visa versa.
  • Parameters
    • bindip is used with the -d switch. The UDP socket will bind to this ip. This is optional, otherwise all IPs are bound to this socket.
    • name is required. It is the name that this socket will be referred to by.
    • localport is optional and is used with -k. If -k and localport are specified, the socket will wait for incoming UDP data on the specified port.
    • ipaddress is the ip of the remote computer you wish to send the data to. This is not required if you are merely opening a socket (-k)
    • remoteport is the port of the remote computer you wish to send the data to. This is only required where ipaddress is required.
    • numbytes is the number of bytes to send, and is used with the -b switch. If this is specified, only numbytes bytes will be sent. Any other data after this $ord(numbytes)) byte is lost.
    • text, %var, &binvar contain the data to be sent.

Examples

sockudp -ktb myudpsocket 5078 host.com 5077 8 You will see this. But not this.

This

  • Trunicates " But not this." because it is past the 8th byte
  • Sends "You will see this." to host.com at port 5077
  • Listens for UDP packets on port 5078

The socket is named myudpsocket, this is the name that would be used in On udpread to read from the socket.

See Also