Using Buffers in TCP Mode
|Top Previous Next|
Once you have allocated memory for the TX and RX buffers you can start sending and receiving data through them. Since TCP is a stream-oriented protocol this is what buffers store- a stream of data being sent and received, without any separation into individual packets. Even for the outgoing data, you have no control over how it will be split into packets for transmission over the network.
Sending data a two-step process. First, you put the data in the TX buffer using the sock.setdata method, and then you perform the actual sending (commit the data) using the sock.send method. For example:
Since this is a two-step process, you may gradually fill the buffer to capacity, and only then send its contents.
The data can be stored in the TX buffer at any time but it will only be sent out if and when the network connection is established. Storing the data in the TX buffer won't cause the socket to establish any connection automatically.
Receiving data is a one-step process. To extract the data from the RX buffer, use the sock.getdata method. Data may only be extracted once from the buffer. Once extracted, it is no longer in the buffer. For example:
The string whatigot now contains up to 255 bytes of data which came from the RX buffer of the socket.
You can also preview the data in the RX buffer without actually extracting it. Use sock.peekdata to achieve this.
Discussion of TCP data RXing continues in Receiving Data in TCP mode.