Xbasic

INET::SSLSocket Class

Description

Properties and methods in the SSLSocket class.

The INET::SSLSocket object is a version of INET::Socket that supports reading and writing data between client and server computers. The following code provides an overview of how socket communications are designed.

Client Computer
Host Computer

dim ServerSocket as INET::Socket dim ClientSocket as INET::Socket dim CTX as INET::SSLContext Define CTX properties ServerSocket.Listen() ServerSocket.Accept(ClientSocket)

dim LocalSocket as INET::Socket LocalSocket.Connect() LocalSocket.Write()

ClientSocket.Read() ClientSocket.Write()

LocalSocket.Read()

There may be more exchanges of data.

LocalSocket.Close()

ClientSocket.Close()

More sessions with other client computers.

ServerSocket.Close()

 Example

This example code shows how to use the methods of the INET::SSLSocket object.

dim ssl as inet::sslsocket
dim Result as C
dim Temp as C
ssl.context.requirevalidcertificate = .f.
if ssl.connect("toshiba1000", 443, 2000) then
    if ssl.write("GET / HTTP/1.0" + crlf() + crlf()) then
        FoundData = ssl.read(temp, 10000, -1)
        while FoundData
            on error resume next
            Result = Result + Temp
            FoundData = .f.
            if ssl.isopen then
                FoundData = ssl.read(temp, 10000, -1)
            end if
        end while
        a5_show_variable(Result, "Test OpenSSL HTTP Client - Response")
    else
        ui_msg_box("Request Error", ssl.callresult.text)
    end if
    ssl.close()
else
    ui_msg_box("Connect Error", ssl.callresult.text)
end if

This code illustrates a simple SSL HTTP Server.

dim ResponseHeader as C
dim ResponseFooter as C
dim ctx as INET::SSLContext
dim ssl as inet::sslsocket
dim doc as inet::httpdocument
dim Request as C
dim Temp as C
ResponseHeader = <<%str%
HTTP/1.1 200 OK
Server: SampleAlphaFiveSSL
Content-Type: text/html

Request
%str%
ResponseFooter = <<%str%

Properties

Context

Context property

IsBusyLogical

Logical IsBusy property

IsOpenLogical

Logical IsOpen property

IsReadableLogical

Logical IsReadable property

IsWriteableLogical

Logical IsWriteable property

RemoteAddressCharacter

String RemoteAddress property

LocalAddressCharacter

String LocalAddress property

RemotePortNumeric

Numeric RemotePort property

LocalPortNumeric

Numeric LocalPort property

HandleNumeric

Numeric Handle property

CallResult

CallResult property

BlockingLogical

Logical Blocking property

BroadcastLogical

Logical Broadcast property

DebugLogical

Logical Debug property

DelayLogical

Logical Delay property

KeepAliveLogical

Logical KeepAlive property

LingerLogical

Logical Linger property

OutOfBandInLineLogical

Logical OutOfBandInLine property

RouteLogical

Logical Route property

ReceiveBufferSizeNumeric

Numeric ReceiveBufferSize property

ReceiveTimeoutNumeric

Numeric ReceiveTimeout property

ReuseAddressLogical

Logical ReuseAddress property

SendBufferSizeNumeric

Numeric SendBufferSize property

SendTimeoutNumeric

Numeric SendTimeout property

BytesAvailableNumeric

Numeric BytesAvailable property

IsListeningLogical

Logical IsListening property

Methods

Accept Method

The INET::SSLSocket::Accept() method accepts a new connection (the socket must already be listening). The method returns a status object with information about the success of the call. If the call is successful, AcceptedSocket contains the new instance of INET::Socket. HandshakeReadTimeout is appropriate for SSL sockets only.

Close Method

The INET::SSLSocket::Close() method closes an open connection.

Connect Method

The INET::SSLSocket::Connect() method opens a connection to the requested host and port. Note: ConnectTimeout is in milliseconds.

CreateCertificateRequest Method

The INET::SSLSocket::CreateCertificateRequest() method creates a request for a certificate.

GetOptions Method

The INET::SSLSocket::GetOptions() method reads the status of one or more option values.

Listen Method

The INET::SSLSocket::Listen() method opens a socket to listen for incoming requests.

Peek Method

The INET::SSLSocket::Peek() method reads characters into a string. Peek does not remove the characters from the receive buffer.

Query_TCP Method

Returns .T. (TRUE) if the TCP connection described by the arguments matches an active connection.

Read Method

The INET::SSLSocket::Read() method reads characters from the connection into a string.

ReadBinary Method

The INET::SSLSocket::ReadBinary() method reads bytes from the connection into a BLOB variable.

ReadLine Method

The INET::SSLSocket::ReadLine() method reads a line from the receive buffer. A line is terminated by a CR-LF. If nothing is available, the method returns an empty string.

ReadUntil Method

Reads from the input stream until the delimiter is encountered or a timeout occurs. If the function returns false, there may still be data in the returned buffer. This means that the read timed out before receiving the delimiter. If ReturnDelimiter is true, the delimiter is returned with the string.

Reconnect Method

The INET::SSLSocket::Reconnect() method reestablishes the connection with an SSL partner (session settings may have changed).

SendFile Method

The INET::SSLSocket::SendFile() method sends the named file.

SetOptions Method

The INET::SSLSocket::SetOptions() methods sets one or more options in a single call.

StartSSLSession Method

The INET::Socket OpenSocket method begins an SSL session with a socket that is already opened. If successful the socket remains secure until closed. If unsuccessful both sockets will be closed. After this call you should no long reference OpenSocket.

Write Method

The INET::SSLSocket::Write() method writes character data to the connection.

WriteBinary Method

The INET::SSLSocket::WriteBinary() method writes binary data to the connection.

See Also