The method ConnectToServerByProxy initiates the TCP connection to the HTTP server through a proxy server.
This method is used to initiate the establishing of a TCP connection to the HTTP server through a proxy server. For the connection request to the proxy server, a function block implementing the interface IF_ProxyHandler must be implemented in your application. This function block must be assigned to the input i_ifProxyHandler.
Once a valid interface has been assigned to the input, the interface methods are called from the function block while establishing a connection to the HTTP server.
The call sequence is as follows:
When the method ConnectToServerByProxy is executed, the interface method ConnectToProxy is called.
If TLS encryption is selected for the connection to the HTTP server, the socket type StartTls is set to TRUE. The method is called cyclically until one of the outputs q_xDone (connection established) or q_xError (unsuccessful connection) indicates TRUE.
After the connection to the proxy server has been established, the interface method ConnectToRemoteServer is called.
If TLS encryption is selected for the connection to the HTTP server, the option UpgradeToTls is set to TRUE. The method is called cyclically until one of the outputs q_xDone (connection established) or q_xError (unsuccessful connection) indicates TRUE.
After the method ConnectToRemoteServer has been completed successfully, the instance of the FB_HttpClient is connected to the remote server. The data exchange with the server using the corresponding methods is possible. The interface IF_ProxyHandler is not required until the next TCP connection is initiated using the method ConnectToServerByProxy.
The return value of the method indicates only whether the connection could be initiated successfully. The status of the connection must be verified using the property State. Evaluate the diagnostic outputs of the method, in case the return value is FALSE. An error indicated by these outputs needs no reset.
If an error is detected during establishing a connection, the interface method Abort of the IF_ProxyHandler is called once.
For more information about the implementation of the interface methods or about implementations already provided, refer to the ProxyCommunicationSupport Library Guide.
Refer to Considerations for Secured Connections Using TLS of the ConnectToServer method.
Stage |
Description |
---|---|
1 |
Initial state: Idle |
2 |
Function call |
3 |
State: Connecting, otherwise an error is detected |
4 |
Final state: Connected, otherwise an error is detected |
Input |
Data type |
Description |
---|---|---|
i_sServerAddress |
STRING[255] |
Specifies the IP address or host name of the server to connect to. |
i_uiServerPort |
UINT |
Specifies the port address of the server. |
i_xUseTls |
BOOL |
Set to TRUE to specify the use of a secured connection using TLS. |
i_stTlsSettings |
TlsSettings |
Specifies the TLS settings for the secured connection. |
i_ifProxyHandler |
PXCS.IF_ProxyHandler |
Function block implementing the interface IF_ProxyHandler providing the methods and properties to implement the additional steps for establishing a connection to an HTTP server through a proxy server. |
Output |
Data type |
Description |
---|---|---|
q_xError |
BOOL |
If this output is set to TRUE, an error has been detected. For details, refer to q_etResult and q_etResultMsg. |
q_etResult |
Provides diagnostic and status information as a numeric value. |
|
q_sResultMsg |
STRING[80] |
Provides additional diagnostic and status information as a text message. |