uCon HomePage

Script Cmd: SOCKET


SOCKET [-acf:t:T:] {subcommand}  [args] ...

This command is basically a superset of the TCP command; hence eliminating the need for that command.  This allows the user to open a TCP or UDP socket and write and/or read data to/from the specified host/port combination.

Options:

-a              convert received data to ASCII prior to pushing into SOCKET shell var (applies to READ)
-c              dump received data to console (applies to READ and FLUSH)
-f {file }      copy received data to specified file (applies to READ and FLUSH)
-t {timeout }   override default timeout of 5 seconds (applies to READ and FLUSH)
-T {tag}        used by OPEN so that subsequent calls to CLOSE/READ/WRITE/FLUSH can optionally reference
                the tag rather than the Hostname (useful when more than one port is opened on the same host)

Current sub-commands supported:

OPEN {Hostname} {Port#} {Protocol}
Opens a socket on the specified hostname.  This can be either a DNS-name or an raw IP address.  As of this writing, Protocol can be either TCP or UDP.

CLOSE
{Hostname | Tag} 
Close the socket previously opened on specified hostname.

READ {Hostname | Tag} {total-to-read}
Reads from previously opened socket...

Use -c to copy all read data to console.
Use -f to copy data to file.
Use -a to have data converted to ascii-coded-hex prior to saving to SOCKET shellvar.

WRITE {Hostname | Tag} {data} 
Write specified data to previously opened socket.

FLUSH {Hostname | Tag}

Keep reading from previously opened socket till no more data...
SOCKET shell var will contain the number of characters flushed.

Use -c to copy all read data to console.
Use -f to copy data to file.


Example1...

            This example shows how the SOCKET command can be used in place of the MONCMD command...

# MONCMD:
SOCKET OPEN 192.168.1.123 777 UDP
SOCKET WRITE 192.168.1.123 "help\n"
SOCKET -c FLUSH 192.168.1.123
SOCKET CLOSE 192.168.1.123
EXIT

Example 2...

            This example shows how SOCKET can be used to hook to an HTTP server.  Notice that this OPEN uses the -T option.

# HTTPGET:
SET HTTPSRVR
SOCKET -T HTTPSRVR OPEN 192.168.1.99 80 TCP
SLEEP 1000
SOCKET WRITE HTTPSRVR "GET /\r\n\r\n"
SOCKET -t2 -f C:/tmp/index_html FLUSH HTTPSRVR
SOCKET CLOSE HTTPSRVR
EXIT