WSProxy Class
Properties Methods Events Configuration Settings Errors
The WSProxy component is used to forward traffic received on a WebSocket to another destination.
Class Name
IPWorksWS_WSProxy
Procedural Interface
ipworksws_wsproxy_open(); ipworksws_wsproxy_close($res); ipworksws_wsproxy_register_callback($res, $id, $function); ipworksws_wsproxy_get_last_error($res); ipworksws_wsproxy_get_last_error_code($res); ipworksws_wsproxy_set($res, $id, $index, $value); ipworksws_wsproxy_get($res, $id, $index); ipworksws_wsproxy_do_config($res, $configurationstring); ipworksws_wsproxy_do_disconnect($res, $connectionid); ipworksws_wsproxy_do_doevents($res); ipworksws_wsproxy_do_shutdown($res);
Remarks
The WSProxy class provides a simple way to accept a WebSocket connection and forward the incoming data to a separate destination host.
The WSProxy 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---> WSProxy ---plain TCP---> Forward Host
In this example the Client establishes a WebSocket connection to the WSProxy component. The WSProxy 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 WSProxy.
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.
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. |
WSPConnectionCount | The number of records in the WSPConnection arrays. |
WSPConnectionConnected | This property is used to disconnect individual connections and/or show their status. |
WSPConnectionConnectionId | This property contains an identifier generated by the component to identify each connection. |
WSPConnectionForwardHost | This property shows the address of the forward host. |
WSPConnectionForwardPort | This property shows the port of the forward host. |
WSPConnectionHost | The Host header value of the connected client. |
WSPConnectionLocalAddress | This property shows the IP address of the interface through which the connection is passing. |
WSPConnectionOrigin | The Origin header value of the connected client. |
WSPConnectionRemoteHost | This property shows the IP address of the connected client. |
WSPConnectionRemotePort | This property shows the port of the connected client. |
WSPConnectionRequestHeaders | The HTTP headers sent by the client in the initial WebSocket connection request. |
WSPConnectionRequestURI | The requested URI sent by the client in the initial WebSocket connection request. |
WSPConnectionSubProtocols | The subprotocols (application-level protocols layered over the WebSocket Protocol) sent by the client in the initial WebSocket connection request. |
WSPConnectionTimeout | A timeout for the component. |
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. |
FirewallAutoDetect | This property tells the component whether or not to automatically detect and use firewall system settings, if available. |
FirewallType | This property determines the type of firewall to connect through. |
FirewallHost | This property contains the name or IP address of firewall (optional). |
FirewallPassword | This property contains a password if authentication is to be used when connecting through the firewall. |
FirewallPort | This property contains the TCP port for the firewall Host . |
FirewallUser | This property contains a user name if authentication is to be used connecting through a firewall. |
Listening | If True, the component 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 component listens. |
SSLAuthenticateClients | If true, the server asks the client(s) for a certificate. |
SSLCertEncoded | The certificate (PEM/base64 encoded). |
SSLCertStore | The name of the certificate store for the client certificate. |
SSLCertStorePassword | If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store. |
SSLCertStoreType | The type of certificate store for this certificate. |
SSLCertSubject | The subject of the certificate used for client authentication. |
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. |
SSLClientAuthentication | Fired when the client presents its credentials to the server. |
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.
WaitForCloseResponse | Determines whether or not the component will forcibly close a connection. |
BufferMessage | Indicates whether or not the entire message is buffered before firing the DataIn event. |
DisconnectStatusCode | Specifies the status code when closing a connection. |
DisconnectStatusDescription | Specifies the message associated with the disconnect status code. |
MaxFrameSize | Specifies the maximum size of the outgoing message in bytes before fragmentation occurs. |
BindExclusively | Whether or not the component considers a local port reserved for exclusive use. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
MaxConnections | The maximum number of connections available. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
RecordLength[ConnectionId] | The length of received data records. |
TcpNoDelay | Whether or not to delay when sending packets. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
BindExclusively | Whether or not the component considers a local port reserved for exclusive use. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
MaxConnections | The maximum number of connections available. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
RecordLength[ConnectionId] | The length of received data records. |
TcpNoDelay | Whether or not to delay when sending packets. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
CodePage | The system code page used for Unicode to Multibyte translations. |