WebSocketProxy Class
Properties Methods Events Configuration Settings Errors
The WebSocketProxy class is used to forward traffic received on a WebSocket to another destination.
Syntax
ipworksws.websocketproxy()
Remarks
The WebSocketProxy class provides a simple way to accept a WebSocket connection and forward the incoming data to a separate destination host.
The WebSocketProxy class is a server that accepts incoming WebSocket connections and will establish an outgoing connection to the specified forward host and forward data it receives onto the final destination. For instance, take this diagram:
Client ---WebSocket protocol---> WebSocketProxy ---plain TCP---> Forward Host
In this example the Client establishes a WebSocket connection to the WebSocketProxy component. The WebSocketProxy class then establishes a separate standard TCP connection to Forward Host. The Client can then communicate with the Forward Host and data will be passed through WebSocketProxy.
To begin using the class first specify a valid value for LocalPort. This is the port on which incoming connections will be accepted. Specify values for DefaultForwardHost and DefaultForwardPort. This is the destination to which the data will be forwarded. Note that you may override these values on a per connection basis if desired when the client connects.
To begin listening set Listening to true.
When a client connects the WebSocketOpenRequest event will fire. To accept the connection simply allow the event to complete. To reject the request set the StatusCode parameter to an HTTP error code (such as 401). You may also set the ForwardHost and ForwardPort event parameters to override the default values.
Once the connection is established all data received on the connection will automatically be forwarded to the forward host. Any data received from the forward host will be sent back to the client. The client is now able to freely communicate with the forward host.
Note: Server components are designed to process events as they occur. To ensure events are processed in a timely manner DoEvents should be called in a loop after the server is started.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
ConnectionBacklog | The maximum number of pending connections maintained by the TCP/IP subsystem. |
Connections | A collection of currently connected WebSocket clients. |
DefaultForwardHost | The default address of the host to which data will be forwarded. |
DefaultForwardPort | The default port of the host to which data will be forwarded. |
DefaultTimeout | An initial timeout value to be used by incoming connections. |
Firewall | A set of properties related to firewall access. |
Listening | If True, the class accepts incoming connections on LocalPort. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
LocalPort | The TCP port in the local host where the class listens. |
SSLAuthenticateClients | If true, the server asks the client(s) for a certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
UseSSL | Determines if SSL is negotiated with incoming connections. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
Config | Sets or retrieves a configuration setting. |
Disconnect | Disconnect the specified client. |
DoEvents | Processes events from the internal message queue. |
Shutdown | Shuts down the server. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
Connected | Fired when a WebSocket is successfully opened. |
ConnectionRequest | Fired when a request for connection comes from a remote host. |
DataIn | Fired when data is received. |
Disconnected | Fired when a WebSocket connection is disconnected. |
Error | Information about errors during data delivery. |
Log | Fires once for each log message. |
SSLClientAuthentication | Fired when the client presents its credentials to the server. |
SSLConnectionRequest | Fires when an SSL connection is requested. |
SSLStatus | Shows the progress of the secure connection. |
WebSocketOpenRequest | Fired when a client attempts to open a WebSocket. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
DataFormat[ConnectionId] | Determines how data is sent. |