%connect_ssl() function

The %connect_ssl() function requests a secure connection between two sockets.

Note: To use this function, the OpenSSL libraries must be installed.

The %connect_ssl() function requests a secure connection between two sockets.


code = %connect_ssl(fd, addr.family, host, port, &ssl_fd);


fd File descriptor of the local socket returned by a previous call to the FlashBASIC C function %socket().
addr.family Specifies the addressing scheme used by the protocol. This field must match the address family used when creating the socket. Valid values are defined in the include file: dm,bp,unix.h socket.h.
host Destination host name. The string must be known to the local network manager. Internally, this calls getaddrinfo to resolve the remote host.
port Port number on the distant host. Legal value for this field depends on the protocol. On TCP/IP, for example, valid port numbers are from 1024 to 32767.
ssl_fd File descriptor of the Secure connection.


To compile successfully, the statement cfunction socket.builtin must be included in the source code.

Upon successful completion, a value of 0 is returned in code, and the ssl_fd FlashBASIC variable is updated.

In the case of an error, the return code is a negative value. The table below lists all of the error return codes:

-1 Socket error, system(0) function is set to the value of errno.
-2 OpenSSL is not installed.
-6 Unable to create a SSL.
-7 Unable to establish the TLS/SSL handshake with the server, the FlashBASIC system(0) function is set to the value of SSL_get_error.

The connection is closed when the socket is closed.


cfunction socket.builtin
include dm,bp,includes sysid.inc
include dm,bp,unix.h socket.h
* Create a socket
* Connect to the distant host
ssl_fd = 0
code=%connect_ssl(fd, af$inet, "prod", 1024, &ssl_fd)
if code < 0 then print "failed to connect"; stop
* Write data to it thru the secure connection
msg="Hello World"
code = %write_ssl(ssl_fd, msg,msglen)
if code < 0 then
   code = %close_ssl(fd, &ssl_fd)
* read from host
Char buffer[100]
code = %read_ssl(ssl_fd, buffer, 100)
if code < 0 then
   code = %close_ssl(fd, &ssl_fd)
print "READ: ":buffer
code = %close_ssl(fd, &ssl_fd)