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]handleHandle of stream to close
Returns
gos_result_t result of api call
Examples:
network/udp_hello_gpio/main.c, and test/throughput/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]hostRemote UDP server host or IP address
[in]remote_portRemote UDP server port
[in]local_portLocal UDP port, set to 0 to use any available port
[out]handle_ptrUDP stream handle
Returns
gos_result_t result of API
Examples:
network/udp_client/main.c, network/udp_hello_gpio/main.c, and test/throughput/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]configConnection configuration, see gos_udp_client_config_t
[out]handle_ptrUDP 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]interfaceInterface to start server, see gos_interface_t
[in]local_portPort for server to listen
[out]handle_ptrUDP stream handle
Returns
gos_result_t result of API
Examples:
test/throughput/main.c.

◆ 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]handleHandle of stream to poll
[out]rx_bytes_availablePointer to hold number of bytes available to read
[out]tx_bytes_availablePointer 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_ipIPv4 address of client
[out]client_portClient 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]handleStream handle returned by API call
[out]dataBuffer to hold read data
[in]max_sizeMaximum amount of data to read
[out]bytes_read_ptrPointer to hold actual amount of data read (set NULL if not used)
Returns
gos_result_t result of api call
Examples:
test/throughput/main.c.

◆ 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
handleStream handle
bufferBuffer 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_bufferBuffer to specify how much data to read, then return how much data was read with pointer to data
[in]hostRemote client host or IPv4 address
[in]remote_portPort of remote client
[in]timeoutMaximum 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]handleStream handle or UDP client or server
[in]receive_handlerHandler 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]dataData to send
[in]sizeSize of data to send
[in]hosthostname or IPv4 address of remote client
[in]portClient'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
Examples:
test/throughput/main.c.

◆ 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]handleStream handle returned by API call
[in]dataData to write to stream
[in]sizeSize of data in bytes to write
Returns
gos_result_t result of api call
Examples:
network/udp_client/main.c, network/udp_hello_gpio/main.c, and test/throughput/main.c.