TCP streaming

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

SDK has the facade API for TCP (wiced_tcp_stream_*), but the stream read function is missing. Whats the status of this API? Is it being incomplete, or is it deprecated? There is also `wiced_tcp_send_buffer`, which seems to have similar semantics to `wiced_tcp_stream_write` + `wiced_tcp_stream_flush`, hence the confusion.

3 Replies
Anonymous
Not applicable
wiced_tcp_send_buffer() was the precursor for the wiced_tcp_stream API and is currently only used by the http protocol library although its use could be replaced with a wiced_tcp_stream_write + flush. The function still exists to offer a simple method of transmitting a large block of data without worrying about splitting it up into separate packets.

The TCP stream API was created to simplify the transmission of data that is generated in a piecemeal fashion. The HTTP server daemon was the main reason for its creation. Reception of data, however, does not occur in the same manner and so there is no wiced_tcp_stream_read() function. The TCP socket has either received a packet or it has not. If a packet has been received it needs to be processed and then freed as soon as possible to ensure optimal packet buffer utilization.

If an application or library requires more data than is provided by a single packet it is the responsibility of that application or library to create temporary storage and copy the data out of the packet.
0 Likes
Anonymous
Not applicable
Reception of data, however, does not occur in the same manner and so there is no wiced_tcp_stream_read() function. The TCP socket has either received a packet or it has not. If a packet has been received it needs to be processed and then freed as soon as possible to ensure optimal packet buffer utilization.

Stream write operation keeps some state in the stream struct (outgoing packet), read could be implemented similarly. Keep receiving packets in a loop (wiced_tcp_receive is blocking), read the data from the packets into a destination buffer until its full or until EOF, store (in the stream struct) one packet + current offset if partially read. All packets are immediately freed, except the last partially read one (no worse than stream write).
0 Likes
Anonymous
Not applicable
What you have suggested is actually implemented in other internal parts of WICED and could be added to the TCP stream API.

Ill add it to the TODO list
0 Likes