UDP Client/Server
UDP client/server functions. More...
Modules | |
Types | |
UDP client/server data types. | |
Functions | |
zos_result_t | zn_udp_connect (const char *host, uint16_t remote_port, uint16_t local_port, uint32_t *handle) |
Connect to remote UDP server. More... | |
zos_result_t | zn_udp_connect_with_config (const zos_udp_client_config_t *config, uint32_t *handle) |
Connect to remote UDP server. More... | |
zos_result_t | zn_udp_listen (zos_interface_t interface, uint16_t local_port, uint32_t *handle) |
Start UDP server. More... | |
zos_result_t | zn_udp_stop_listening (void) |
Stop UDP server on specified interface. More... | |
zos_result_t | zn_udp_read (uint32_t handle, void *data, uint32_t max_size, uint32_t *bytes_read) |
Read UDP stream data. More... | |
zos_result_t | zn_udp_read_with_buffer (uint32_t handle, zos_buffer_t *buffer) |
Read UDP stream data into buffer. More... | |
zos_result_t | zn_udp_write (uint32_t handle, const void *data, uint32_t size) |
Write UDP stream data. More... | |
zos_result_t | zn_udp_close (uint32_t handle) |
Close UDP stream. More... | |
zos_result_t | zn_udp_poll (uint32_t handle, uint32_t *bytes_available) |
Poll UDP stream for RX data. More... | |
zos_result_t | zn_udp_query (uint32_t *client_ip, uint16_t *client_port) |
Get current UDP server client info. More... | |
zos_result_t | zn_udp_sendto (const void *data, uint32_t size, const char *host, uint16_t port) |
Send data to specific remote IP address/port. More... | |
zos_result_t | zn_udp_receivefrom (zos_buffer_t *data_buffer, const char *host, uint16_t remote_port, uint32_t timeout) |
Receive data from specific remote host/port. More... | |
zos_result_t | zn_udp_register_receive_event_handler (uint32_t handle, zos_stream_event_handler_t receive_handler) |
Register UDP data received event handler. More... | |
Detailed Description
UDP client/server functions.
Function Documentation
zos_result_t zn_udp_close | ( | uint32_t | handle | ) |
Close UDP stream.
See ZentriOS Command API documentation: stream_close.
- Parameters
-
[in] handle
Handle of stream to close
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_connect | ( | const char * | host, |
uint16_t | remote_port, |
||
uint16_t | local_port, |
||
uint32_t * | handle |
||
) |
Connect to remote UDP server.
See ZentriOS Command API documentation: udp_client.
- Parameters
-
[in] host
Remote UDP server host or IP address [in] remote_port
Remote UDP server port [in] local_port
Local UDP port, set to 0 to use any available port [out] handle
UDP stream handle
- Returns
- zos_result_t result of API
zos_result_t zn_udp_connect_with_config | ( | const zos_udp_client_config_t * | config, |
uint32_t * | handle |
||
) |
Connect to remote UDP server.
See ZentriOS Command API documentation: udp_client.
- Parameters
-
[in] config
Connection configuration, see zos_udp_client_config_t [out] handle
UDP stream handle
- Returns
- zos_result_t result of API
zos_result_t zn_udp_listen | ( | zos_interface_t | interface, |
uint16_t | local_port, |
||
uint32_t * | handle |
||
) |
Start UDP server.
See ZentriOS Command API documentation: udp_server start.
- Parameters
-
[in] interface
Interface to start server, see zos_interface_t [in] local_port
Port for server to listen [out] handle
UDP stream handle
- Returns
- zos_result_t result of API
zos_result_t zn_udp_poll | ( | uint32_t | handle, |
uint32_t * | bytes_available |
||
) |
Poll UDP stream for RX data.
- Parameters
-
[in] handle
Handle of stream to poll [out] bytes_available
Pointer to hold number of bytes available to read
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_query | ( | uint32_t * | client_ip, |
uint16_t * | client_port |
||
) |
Get current UDP server client info.
See ZentriOS Command API documentation: udp_server read -q.
- Parameters
-
[out] client_ip
IPv4 address of client [out] client_port
Client remote port
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_read | ( | uint32_t | handle, |
void * | data, |
||
uint32_t | max_size, |
||
uint32_t * | bytes_read |
||
) |
Read UDP stream data.
See ZentriOS Command API documentation: stream_read.
- Parameters
-
[in] handle
Stream handle returned by API call [out] data
Buffer to hold read data [in] max_size
Maximum amount of data to read [out] bytes_read
Pointer to hold actual amount of data read (set NULL if not used)
- Returns
- zos_result_t result of api call
- Examples:
- basic/udp_client/udp_client.c.
zos_result_t zn_udp_read_with_buffer | ( | uint32_t | handle, |
zos_buffer_t * | buffer |
||
) |
Read UDP stream data into buffer.
See zn_read_with_buffer() for more information.
- Parameters
-
handle
Stream handle buffer
Buffer 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_udp_receivefrom | ( | zos_buffer_t * | data_buffer, |
const char * | host, |
||
uint16_t | remote_port, |
||
uint32_t | timeout |
||
) |
Receive data from specific remote host/port.
See zn_read_with_buffer() for details on how the data_buffer argument is used.
See ZentriOS Command API documentation: udp_server write
- Parameters
-
[in,out] data_buffer
Buffer to specify how much data to read, then return how much data was read with pointer to data [in] host
Remote client host or IPv4 address [in] remote_port
Port of remote client [in] timeout
Maximum time in milliseconds to wait for RX data
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_register_receive_event_handler | ( | uint32_t | handle, |
zos_stream_event_handler_t | receive_handler |
||
) |
Register UDP data received event handler.
The registers a receive handler for either a UDP client or server.
- Note
- The event handler executes in the Zap Thread context
- Parameters
-
[in] handle
Stream handle or UDP client or server [in] receive_handler
Handler to be issued when UDP client/server has data to be read
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_sendto | ( | const void * | data, |
uint32_t | size, |
||
const char * | host, |
||
uint16_t | port |
||
) |
Send data to specific remote IP address/port.
See ZentriOS Command API documentation: udp_server write
- Parameters
-
[in] data
Data to send [in] size
Size of data to send [in] host
hostname or IPv4 address of remote client [in] port
Client's UDP port
- Returns
- zos_result_t result of api call
zos_result_t zn_udp_stop_listening | ( | void |
| ) |
Stop UDP server on specified interface.
See ZentriOS Command API documentation: udp_server stop.
- Returns
- zos_result_t result of API
zos_result_t zn_udp_write | ( | uint32_t | handle, |
const void * | data, |
||
uint32_t | size |
||
) |
Write UDP stream data.
See ZentriOS Command API documentation: stream_write.
- Parameters
-
[in] handle
Stream handle returned by API call [in] data
Data to write to stream [in] size
Size of data in bytes to write
- Returns
- zos_result_t result of api call