TCP/TLS Client/Server

TCP/TLS client/server functions. More...

Modules

Types
TCP client/server types.
 

Functions

zos_result_t zn_tcp_connect (zos_interface_t interface, const char *host, uint16_t port, uint32_t *handle)
 Connect to remote TCP server. More...
 
zos_result_t zn_tls_connect (zos_interface_t interface, const char *host, uint16_t port, uint32_t *handle)
 Connect to remote TCP server with TLS security. More...
 
zos_result_t zn_tcp_connect_with_config (const zos_tcp_config_t *config, uint32_t *handle)
 Connect to remote TCP/TLS server with configuration. More...
 
zos_result_t zn_tcp_listen (zos_interface_t interface, uint16_t port)
 Start TCP server. More...
 
zos_result_t zn_tcp_stop_listening (void)
 Stop TCP server. More...
 
zos_result_t zn_tls_listen (zos_interface_t interface, uint16_t port)
 Start TCP server with TLS security. More...
 
zos_result_t zn_tls_stop_listening (void)
 Stop TLS server. More...
 
zos_result_t zn_tcp_disconnect (uint32_t handle)
 Close TCP/TLS stream. More...
 
zos_result_t zn_tcp_read (uint32_t handle, void *data, uint32_t max_size, uint32_t *bytes_read)
 Read TCP/TLS stream data. More...
 
zos_result_t zn_tcp_read_with_buffer (uint32_t handle, zos_buffer_t *buffer)
 Read TCP stream data into buffer. More...
 
zos_result_t zn_tcp_write (uint32_t handle, const void *data, uint32_t size, zos_bool_t auto_flush)
 Write TCP/TLS stream data. More...
 
zos_result_t zn_tcp_poll (uint32_t handle, uint32_t *bytes_available)
 Poll TCP/TLS stream for RX data. More...
 
zos_result_t zn_tcp_register_client_event_handlers (uint32_t handle, zos_stream_event_handler_t disconnect, zos_stream_event_handler_t receive)
 Register TCP/TLS client event handlers. More...
 
void zn_tcp_register_server_event_handlers (zos_stream_event_handler_t connect, zos_stream_event_handler_t disconnect, zos_stream_event_handler_t receive)
 Register TCP/TLS server event handlers. More...
 
zos_result_t zn_tcp_get_client_info (uint32_t handle, char *host_buffer, uint8_t buffer_len, uint16_t *port)
 Get TCP/TLS client info. More...
 

Detailed Description

TCP/TLS client/server functions.

Function Documentation

zos_result_t zn_tcp_connect ( zos_interface_t  interface,
const char *  host,
uint16_t  port,
uint32_t *  handle 
)

Connect to remote TCP server.

See ZentriOS Command API documentation: tcp_client.

Parameters
[in]interfaceInterface to open connection
[in]hosthostname or IPv4 address of remote server
[in]portListening port of remote TCP server
[out]handleStream handle of connection
Returns
result of api, see zos_result_t
zos_result_t zn_tcp_connect_with_config ( const zos_tcp_config_t config,
uint32_t *  handle 
)

Connect to remote TCP/TLS server with configuration.

See ZentriOS Command API documentation: tcp_client.

See zn_tcp_register_client_event_handlers() for registering event handlers.

Parameters
[in]configConnection configuration, see zos_tcp_config_t
[out]handleStream handle of connection
Returns
result of api, see zos_result_t
zos_result_t zn_tcp_disconnect ( uint32_t  handle)

Close TCP/TLS stream.

See ZentriOS Command API documentation: stream_close.

Parameters
[in]handleHandle of stream to close
Returns
zos_result_t result of api call
Examples:
basic/tcp_client/tcp_client.c, and demo/pong/link_client.c.
zos_result_t zn_tcp_get_client_info ( uint32_t  handle,
char *  host_buffer,
uint8_t  buffer_len,
uint16_t *  port 
)

Get TCP/TLS client info.

See ZentriOS Command API documentation: stream_list.

zos_result_t zn_tcp_listen ( zos_interface_t  interface,
uint16_t  port 
)

Start TCP server.

See ZentriOS Command API documentation: tcp_server start.

See zn_tcp_register_server_event_handlers() for registering client event handlers.

Parameters
[in]interfaceInterface to start server
[in]portListening port of TCP server
Returns
result of api, see zos_result_t
zos_result_t zn_tcp_poll ( uint32_t  handle,
uint32_t *  bytes_available 
)

Poll TCP/TLS stream for RX data.

Parameters
[in]handleHandle of stream to poll
[out]bytes_availablePointer to hold number of bytes available to read
Returns
zos_result_t result of api call
zos_result_t zn_tcp_read ( uint32_t  handle,
void *  data,
uint32_t  max_size,
uint32_t *  bytes_read 
)

Read TCP/TLS stream data.

See ZentriOS Command API documentation: stream_read.

Parameters
[in]handleStream handle returned by API call
[out]dataBuffer to hold read data
[in]max_sizeMaximum amount of data to read
[out]bytes_readPointer to hold actual amount of data read (set NULL if not used)
Returns
zos_result_t result of api call
Examples:
basic/softap_tcp_server/softap_tcp_server.c, basic/tcp_client/tcp_client.c, and demo/pong/link.c.
zos_result_t zn_tcp_read_with_buffer ( uint32_t  handle,
zos_buffer_t buffer 
)

Read TCP stream data into buffer.

See zn_read_with_buffer() for more information.

Parameters
handleStream handle
bufferBuffer to specify how much data to read, then return how much data was read with pointer to data
Returns
zos_result_t result of api call
zos_result_t zn_tcp_register_client_event_handlers ( uint32_t  handle,
zos_stream_event_handler_t  disconnect,
zos_stream_event_handler_t  receive 
)

Register TCP/TLS client event handlers.

The client connection should have been previously opened with:

Note
The event handlers execute in the Zap thread context
Parameters
[in]handleClient stream handle
[in]disconnectClient disconnect event handler
[in]receiveClient receive data event handler
Returns
zos_result_t result of api call
Examples:
basic/tcp_client/tcp_client.c, and demo/pong/link_client.c.
void zn_tcp_register_server_event_handlers ( zos_stream_event_handler_t  connect,
zos_stream_event_handler_t  disconnect,
zos_stream_event_handler_t  receive 
)

Register TCP/TLS server event handlers.

Register event handlers for TCP server client events. The TCP server must first be started with:

Note
The event handlers execute in the Zap thread context
Parameters
[in]connectclient connect event handler
[in]disconnectclient disconnect event handler
[in]receiveclient data received event handler
Examples:
basic/softap_tcp_server/softap_tcp_server.c, and demo/pong/link_server.c.
zos_result_t zn_tcp_stop_listening ( void  )

Stop TCP server.

See ZentriOS Command API documentation: tcp_server stop.

Returns
result of api, see zos_result_t
zos_result_t zn_tcp_write ( uint32_t  handle,
const void *  data,
uint32_t  size,
zos_bool_t  auto_flush 
)

Write TCP/TLS stream data.

See ZentriOS Command API documentation: stream_write.

Parameters
[in]handleStream handle returned by API call
[in]dataData to write to stream
[in]sizeSize of data in bytes to write
[in]auto_flushIf ZOS_TRUE, only flush data when the internal buffer is full, ZOS_FALSE flush the data immediately
Returns
zos_result_t result of api call
Examples:
basic/softap_tcp_server/softap_tcp_server.c, basic/tcp_client/tcp_client.c, and demo/pong/link.c.
zos_result_t zn_tls_connect ( zos_interface_t  interface,
const char *  host,
uint16_t  port,
uint32_t *  handle 
)

Connect to remote TCP server with TLS security.

See ZentriOS Command API documentation: tls_client.

See zn_tcp_register_client_event_handlers() for registering event handlers.

Parameters
[in]interfaceInterface to open connection
[in]hosthostname or IPv4 address of remote server
[in]portListening port of TCP server
[out]handleStream handle of connection
Returns
result of api, see zos_result_t
zos_result_t zn_tls_listen ( zos_interface_t  interface,
uint16_t  port 
)

Start TCP server with TLS security.

See ZentriOS Command API documentation: tls_server start.

See zn_tcp_register_server_event_handlers() for registering client event handlers.

Parameters
[in]interfaceInterface to start server
[in]portListening port of TLS server
Returns
result of api, see zos_result_t
zos_result_t zn_tls_stop_listening ( void  )

Stop TLS server.

See ZentriOS Command API documentation: tls_server stop.

Returns
result of api, see zos_result_t