UDP Client/Server

UDP client/server functions. More...

Modules

Types
UDP client/server data types.

Functions

gos_result_t gos_udp_connect (const char *host, uint16_t remote_port, uint16_t local_port, gos_handle_t *handle_ptr)
Connect to remote UDP server. More...
gos_result_t gos_udp_connect_with_config (const gos_udp_client_config_t *config, gos_handle_t *handle_ptr)
Connect to remote UDP server. More...
gos_result_t gos_udp_listen ( gos_interface_t interface, uint16_t local_port, gos_handle_t *handle_ptr)
Start UDP server. More...
gos_result_t gos_udp_stop_listening (void)
Stop UDP server on specified interface. More...
gos_result_t gos_udp_read ( gos_handle_t handle, void *data, uint32_t max_size, uint32_t *bytes_read_ptr)
Read UDP stream data. More...
gos_result_t gos_udp_read_with_buffer ( gos_handle_t handle, gos_buffer_t *buffer)
Read UDP stream data into buffer. More...
gos_result_t gos_udp_write ( gos_handle_t handle, const void *data, uint32_t size)
Write UDP stream data. More...
gos_result_t gos_udp_close ( gos_handle_t handle)
Close UDP stream. More...
gos_result_t gos_udp_poll ( gos_handle_t handle, uint32_t *rx_bytes_available, uint32_t *tx_bytes_available)
Poll UDP stream for RX data. More...
gos_result_t gos_udp_query (uint32_t *client_ip, uint16_t *client_port)
Get current UDP server client info. More...
gos_result_t gos_udp_sendto (const void *data, uint32_t size, const char *host, uint16_t port)
Send data to specific remote IP address/port. More...
gos_result_t gos_udp_receivefrom ( gos_buffer_t *data_buffer, const char *host, uint16_t remote_port, uint32_t timeout)
Receive data from specific remote host/port. More...
gos_result_t gos_udp_register_receive_event_handler ( gos_handle_t handle, gos_stream_event_handler_t receive_handler)
Register UDP data received event handler. More...

Detailed Description

UDP client/server functions.

Function Documentation

gos_udp_close()

gos_result_t gos_udp_close ( gos_handle_t handle )

Close UDP stream.

See Gecko OS Command API documentation: stream_close .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of stream to close
Returns
gos_result_t result of api call
Examples:
network/udp_hello_gpio/main.c .

gos_udp_connect()

gos_result_t gos_udp_connect ( const char * host,
uint16_t remote_port,
uint16_t local_port,
gos_handle_t * handle_ptr
)

Connect to remote UDP server.

See Gecko OS 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_ptr UDP stream handle
Returns
gos_result_t result of API
Examples:
network/udp_client/main.c , and network/udp_hello_gpio/main.c .

gos_udp_connect_with_config()

gos_result_t gos_udp_connect_with_config ( const gos_udp_client_config_t * config,
gos_handle_t * handle_ptr
)

Connect to remote UDP server.

See Gecko OS Command API documentation: udp_client .

Parameters
[in] config Connection configuration, see gos_udp_client_config_t
[out] handle_ptr UDP stream handle
Returns
gos_result_t result of API

gos_udp_listen()

gos_result_t gos_udp_listen ( gos_interface_t interface,
uint16_t local_port,
gos_handle_t * handle_ptr
)

Start UDP server.

See Gecko OS Command API documentation: udp_server start .

Parameters
[in] interface Interface to start server, see gos_interface_t
[in] local_port Port for server to listen
[out] handle_ptr UDP stream handle
Returns
gos_result_t result of API

gos_udp_poll()

gos_result_t gos_udp_poll ( gos_handle_t handle,
uint32_t * rx_bytes_available,
uint32_t * tx_bytes_available
)

Poll UDP stream for RX data.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
Parameters
[in] handle Handle of stream to poll
[out] rx_bytes_available Pointer to hold number of bytes available to read
[out] tx_bytes_available Pointer to hold available TX buffer space
Returns
gos_result_t result of api call
Examples:
network/udp_client/main.c .

gos_udp_query()

gos_result_t gos_udp_query ( uint32_t * client_ip,
uint16_t * client_port
)

Get current UDP server client info.

See Gecko OS Command API documentation: udp_server read -q .

Parameters
[out] client_ip IPv4 address of client
[out] client_port Client remote port
Returns
gos_result_t result of api call

gos_udp_read()

gos_result_t gos_udp_read ( gos_handle_t handle,
void * data,
uint32_t max_size,
uint32_t * bytes_read_ptr
)

Read UDP stream data.

See Gecko OS Command API documentation: stream_read .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
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_ptr Pointer to hold actual amount of data read (set NULL if not used)
Returns
gos_result_t result of api call

gos_udp_read_with_buffer()

gos_result_t gos_udp_read_with_buffer ( gos_handle_t handle,
gos_buffer_t * buffer
)

Read UDP stream data into buffer.

See gos_read_with_buffer() for more information.

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
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
gos_result_t result of api call
Examples:
network/udp_client/main.c .

gos_udp_receivefrom()

gos_result_t gos_udp_receivefrom ( gos_buffer_t * data_buffer,
const char * host,
uint16_t remote_port,
uint32_t timeout
)

Receive data from specific remote host/port.

See gos_read_with_buffer() for details on how the data_buffer argument is used.

See Gecko OS 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
gos_result_t result of api call

gos_udp_register_receive_event_handler()

gos_result_t gos_udp_register_receive_event_handler ( gos_handle_t handle,
gos_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 app Thread context
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
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
gos_result_t result of api call
Examples:
network/udp_client/main.c .

gos_udp_sendto()

gos_result_t gos_udp_sendto ( const void * data,
uint32_t size,
const char * host,
uint16_t port
)

Send data to specific remote IP address/port.

See Gecko OS 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
gos_result_t result of api call

gos_udp_stop_listening()

gos_result_t gos_udp_stop_listening ( void )

Stop UDP server on specified interface.

See Gecko OS Command API documentation: udp_server stop .

Returns
gos_result_t result of API

gos_udp_write()

gos_result_t gos_udp_write ( gos_handle_t handle,
const void * data,
uint32_t size
)

Write UDP stream data.

See Gecko OS Command API documentation: stream_write .

Note
Stream handles start at 1, max handle value is GOS_MAX_STREAMS
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
gos_result_t result of api call
Examples:
network/udp_client/main.c , and network/udp_hello_gpio/main.c .