Reference Manual


ws - interact with WebSocket clients
ws register name
ws write index | name | * "text string"
ws exec  index | name | * func arg
ws close [index | name | *]




When invoked with no arguments, ws prints details of all current WebSocket connections. The first number printed is the connection index that can be used in other commands to specify the connection over which an operation is to be performed.

Command ws register name notifies NAT32 that element name on the page that issued the command is to receive ws write, ws exec and ws close commands.

Command ws write sends the specified text to the WebSocket specified by index or name. The text will appear in the div element specified in the wsInit call of the page that created the WebSocket. If no WebSockets exist at the time, the text is printed on the CONSOLE device.

Command ws exec sends the specified Javascript function name and argument to the WebSocket specified by index or name. If the function exists, it will be called as func(arg). Otherwise, func:arg is sent to the WebSocket's div element.

Command ws close closes the WebSocket specified by index or name. All existing WebSockets are closed if no index or name is specified or if * is specified.

A WebSocket from a client to the NAT32 HTTPD is created by invoking the Javascript function wsInit('name') on a page that has included the file ws.js. Similarly, the Javascript function wsInit(0) can be executed to close the WebSocket.

The Javascript onopen event handler then issues a ws register name command so that the named page element is associated with the WebSocket. The element would normally be a div with an ID matching the name. From then on, ws write, ws exec and ws close commands can be used.

NAT32 ws commands can be issued to any web client that has a WS entry in the WinSock sockets table. The special value * denotes all connections.

WebSockets are particularly useful when a web page invokes functionality that needs to convey information back to the page asynchronously. For example, when a VPN connection is established via a web page served by NAT32's HTTPD, the page will receive connection status information as it becomes available.

WebSockets can also be used to view NAT32 Monitor output on a client PC. The command set notify status will cause Monitor output to be sent to all current WebSockets for display in the client's status div. Note that the Monitor dialog box on the NAT32 machine must be enabled for this to work.

Open a WebSocket. Close the WebSocket. Display a string on all pages that have an open WebSocket.
HTTPD, Monitor, Honeypot Monitor