base.Channel.openClientSocket()

Before a channel object can be used, a channel associated with it must be opened. It can be either a file, a socket or a pipe. If a channel is not opened, any other methods associated with it will have no effect and will return a runtime error.

The OpenClientSocket() method is used to set up a TCP connection with a server. The method invocation needs four arguments to be passed, the host name, the port number, the opening flags and the timeout value:

CALL chan_obj.openClientSocket(host, port_number, opening_flag, timeout)

 

The host argument is the quoted string or a variable containing the name or the IP address of the host machine to connect to. The port number should be an integer value specifying the service port number. The timeout argument should contain an integer value specifying the timeout in seconds after which the program will no longer wait for the response from the socket. If it is set to -1 the timeout is disabled and the program will wait for the response forever.

The opening_flags is a quoted string or a variable containing one or two opening flags, which are listed in the following table:

Mode

Flag

Effect

Read Mode

r

Specifies that the program only reads from the socket and does not write to it.

Write Mode

w

Specifies that the program only writes to the socket and does not read from it.

Read and Write Mode

u

The program reads from and writes to the socket.

Binary Mode

b

The socket will be opened in a binary mode to avoid the translation of the carriage return and line feed symbols.

 

Below is given an example of the method usage:

CALL chan_obj.openClientSocket("localhost", 9090, "ub", 50)