|
| TCPClient () |
| Construct a new TCPClient object. You will do this for each TCP client connection. More...
|
|
| TCPClient (sock_handle_t sock) |
| Construct a new TCPClient object. You will not generally use this overload, it's used internally.
|
|
virtual | ~TCPClient () |
| Destroy the TCPClient object. This will close the connection if necessary and release its resources.
|
|
uint8_t | status () |
| Returns true if the network socket is open and the underlying network is ready. More...
|
|
virtual int | connect (IPAddress ip, uint16_t port, network_interface_t=0) |
| Connect to a host by IP address. More...
|
|
virtual int | connect (const char *host, uint16_t port, network_interface_t=0) |
| Connect to a host by its DNS hostname. More...
|
|
virtual size_t | write (uint8_t b) |
| Writes a single byte to the remote host. More...
|
|
virtual size_t | write (const uint8_t *buffer, size_t size) |
| Writes a buffer of data to the remote host. More...
|
|
virtual size_t | write (uint8_t b, system_tick_t timeout) |
| Writes a single byte to the remote host. More...
|
|
virtual size_t | write (const uint8_t *buffer, size_t size, system_tick_t timeout) |
| Writes a buffer of data to the remote host. More...
|
|
virtual int | available () |
| Returns the number of bytes available to read. More...
|
|
virtual int | read () |
| Read a single byte from the receive buffer. More...
|
|
virtual int | read (uint8_t *buffer, size_t size) |
| Read a buffer of data from the receive buffer. More...
|
|
virtual int | peek () |
| Look at the next byte will be read, without removing it from the input buffer. More...
|
|
virtual void | flush () |
| Blocks until all data waiting to be sent in the W5500 send buffer has been sent.
|
|
void | flush_buffer () |
| Discards data waiting to be read from the internal buffer. More...
|
|
virtual void | stop () |
| End this connection, release its resources. More...
|
|
virtual uint8_t | connected () |
| Returns true if there is data waiting to be read or if currently connected to the remote host. More...
|
|
virtual | operator bool () |
| Equivalent to status() != 0, but as the bool() operator, making it easy to test if there is a connection. More...
|
|
virtual IPAddress | remoteIP () |
| Return the IP address of the other side of the connection. More...
|
|
virtual size_t | write (uint8_t c)=0 |
| Write a single byte to the stream or file. More...
|
|
size_t | write (const char *str) |
| Write a null-terminated c-string the stream or file. More...
|
|
virtual size_t | write (const uint8_t *buffer, size_t size) |
| Write a bytes specified by a buffer and length to the stream or file. More...
|
|
TCPClient class used to access the isolated Ethernet.
Replace TCPClient
with IsolatedEthernet::TCPClient
to use Ethernet instead of the Particle device's native networking (cellular or Wi-Fi).
virtual int IsolatedEthernet::TCPClient::available |
( |
| ) |
|
|
virtual |
Returns the number of bytes available to read.
- Returns
- int number of bytes
Note that the receive buffer is only 2048 bytes on the W5500. Thus the other side of the connection may be holding more data that has not been received by the W5500 yet.
If you are expecting a fixed-size structure, you should always read out all available bytes on each loop into a separate buffer and process when it has been read completely. Do not wait for available() to be the size of the structure then read.
virtual int IsolatedEthernet::TCPClient::read |
( |
uint8_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
virtual |
Read a buffer of data from the receive buffer.
- Parameters
-
buffer | A pointer to a buffer to read data into |
size | Number of bytes to read, must be > 0. |
- Returns
- int the number of bytes read, or a negative value on error
This is much more efficient to read data into a buffer using this call instead of reading one byte at a time. The number of bytes read is not guaranteed to be size requested; if any bytes are available they will be copied to buffer and the result will be the number of bytes actually read.
The optimize request size is 2048 bytes, which is the size of the incoming data buffer. Making it larger will have no effect since there will never be more bytes in the buffer.
virtual size_t IsolatedEthernet::TCPClient::write |
( |
const uint8_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
virtual |
Writes a buffer of data to the remote host.
- Parameters
-
buffer | Pointer to a buffer of bytes to send (can be binary or ASCII) |
size | Number of bytes to send. |
- Returns
- size_t The number of bytes written, typically 1.
Internally, the W5500 can't buffer more than 2048 bytes of data, however this library will break up your send into chunks to fit in the available buffer space.
This overload does not take a timeout and uses the default timeout of 30 seconds. The timeout is for the whole send, not individual chunks. If the timeout is exceeded there is no guarantee of how many bytes were actually sent.
There's a bug in Device OS where the write function can also return a negative error code from write(), however size_t is unsigned, so it tends to return as a very large positive integer instead. Because of this, it's best to ignore the result or test for != 1.
virtual size_t IsolatedEthernet::TCPClient::write |
( |
const uint8_t * |
buffer, |
|
|
size_t |
size, |
|
|
system_tick_t |
timeout |
|
) |
| |
|
virtual |
Writes a buffer of data to the remote host.
- Parameters
-
buffer | Pointer to a buffer of bytes to send (can be binary or ASCII) |
size | Number of bytes to send. |
timeout | Timeout in milliseconds, or 0 to wait forever |
- Returns
- size_t The number of bytes written, typically 1.
Internally, the W5500 can't buffer more than 2048 bytes of data, however this library will break up your send into chunks to fit in the available buffer space.
The timeout is for the whole send, not individual chunks. If the timeout is exceeded there is no guarantee of how many bytes were actually sent.
There's a bug in Device OS where the write function can also return a negative error code from write(), however size_t is unsigned, so it tends to return as a very large positive integer instead. Because of this, it's best to ignore the result or test for != 1.
virtual size_t IsolatedEthernet::TCPClient::write |
( |
uint8_t |
b | ) |
|
|
virtual |
Writes a single byte to the remote host.
- Parameters
-
b | The byte to write (can be ASCII or binary). |
- Returns
- size_t The number of bytes written, typically 1.
This overload does not take a timeout and uses the default timeout of 30 seconds.
It's best to use the overload that takes a buffer and a size. Each byte write is communicated to the W5500 using SPI calls. The W5500 may further buffer the data before assembling it in packets, but using the buffer-based approach is still much faster.
There's a bug in Device OS where the write function can also return a negative error code from write(), however size_t is unsigned, so it tends to return as a very large positive integer instead. Because of this, it's best to ignore the result or test for != 1.
virtual size_t IsolatedEthernet::TCPClient::write |
( |
uint8_t |
b, |
|
|
system_tick_t |
timeout |
|
) |
| |
|
virtual |
Writes a single byte to the remote host.
- Parameters
-
b | The byte to write (can be ASCII or binary). |
timeout | Timeout in milliseconds, or 0 to wait forever |
- Returns
- size_t The number of bytes written, typically 1.
It's best to use the overload that takes a buffer and a size. Each byte write is communicated to the W5500 using SPI calls. The W5500 may further buffer the data before assembling it in packets, but using the buffer-based approach is still much faster.
There's a bug in Device OS where the write function can also return a negative error code from write(), however size_t is unsigned, so it tends to return as a very large positive integer instead. Because of this, it's best to ignore the result or test for != 1.