IsolatedEthernet
|
Replacement for TCPServer class to use Ethernet. More...
#include <IsolatedEthernet.h>
Public Member Functions | |
TCPServer (uint16_t port, network_interface_t nif=0) | |
Construct a new TCPServer object. This is safe as a globally constructed object. More... | |
~TCPServer () | |
Destroy the TCPServer object, free the underlying listening socket. More... | |
IsolatedEthernet::TCPClient | available () |
If a connection has been made to this server, returns it. More... | |
virtual bool | begin () |
Starts a server listening for a connection. More... | |
virtual size_t | write (uint8_t b) |
Writes a single byte to most recently connected remote host. Do not use this method! More... | |
virtual size_t | write (const uint8_t *buf, size_t size) |
Writes a buffer of data to the remote host. Do not use this method! More... | |
virtual size_t | write (uint8_t b, system_tick_t timeout) |
Writes a single byte to the remote host. Do not use this method! More... | |
virtual size_t | write (const uint8_t *buf, size_t size, system_tick_t timeout) |
Writes a buffer of data to the remote host. Do not use this method! More... | |
void | stop () |
Stop accepting connections. More... | |
int | getWriteError () |
Return the last error code. 0 means no error. | |
void | clearWriteError () |
Clear the last error code to 0. | |
size_t | print (const char[]) |
Print a null-terminated array of char variables (a c-string) to the stream or file. | |
size_t | print (char) |
Print a single character to the stream or file. | |
size_t | print (unsigned char value, int base=DEC) |
Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file. More... | |
size_t | print (int value, int base=DEC) |
Print an int (32 bit integer) the specified base to the stream or file. More... | |
size_t | print (unsigned int value, int base=DEC) |
Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file. More... | |
size_t | print (long value, int base=DEC) |
Print a long (32 bit integer) the specified base to the stream or file. More... | |
size_t | print (unsigned long value, int base=DEC) |
Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file. More... | |
size_t | print (double value, int dec=2) |
Print a double floating point value to the stream or file. More... | |
size_t | print (const Printable &) |
Print an object derived from Printable to the stream or file. | |
size_t | println (const char[]) |
Print a null-terminated array of char variables (a c-string) plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (char value) |
Print a single character plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (unsigned char value, int base=DEC) |
Print an unsigned char (byte value. 8 bits) in the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (int value, int base=DEC) |
Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or file. More... | |
size_t | println (unsigned int value, int base=DEC) |
Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (long value, int base=DEC) |
Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (unsigned long value, int base=DEC) |
Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (double value, int dec=2) |
Print a double floating point value plus a CRLF end-of-line terminator to the stream or file. More... | |
size_t | println (const Printable &) |
Print an object derived from Printable plus a CRLF end-of-line terminator to the stream or file. | |
size_t | println (void) |
Print a CRLF end-of-line terminator to the stream or file. | |
template<typename... Args> | |
size_t | printf (const char *format, Args... args) |
Print using printf-style formatting to the stream or file. More... | |
template<typename... Args> | |
size_t | printlnf (const char *format, Args... args) |
Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file. More... | |
Replacement for TCPServer class to use Ethernet.
Replace TCPServer
with IsolatedEthernet::TCPServer
to use Ethernet instead of the Particle device's native networking (cellular or Wi-Fi).
Note that IsolatedEthernet::TCPServer
can be used on cellular devices that normally do not support server mode (Boron, B Series SoM, etc.).
IsolatedEthernet::TCPServer::TCPServer | ( | uint16_t | port, |
network_interface_t | nif = 0 |
||
) |
Construct a new TCPServer object. This is safe as a globally constructed object.
port | The port number to bind to, or 0 for any available port. |
nif | Ignored |
|
inline |
IsolatedEthernet::TCPClient IsolatedEthernet::TCPServer::available | ( | ) |
If a connection has been made to this server, returns it.
The pattern typically used is: TCPClient client = server.available(); if (client) { // Handle client stuff here client.stop(); }
When a connection arrives, a new listener is created to handle another connection. There is no setting for the maximum number of clients for a particular server, though you can manage that by immediately closing clients using stop() when there are too many connections. You're still limited to the maximum of 8 sockets on the W5500.
|
virtual |
Starts a server listening for a connection.
This should only be done after IsolatedEthernet().instance().ready() is true (the PHY link is up and the device has an IP address.)
|
inherited |
Print a double floating point value to the stream or file.
value | The value to print. |
dec | The number of decimal places to include for the fractional part. Default: 2 |
|
inherited |
Print an int (32 bit integer) the specified base to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print a long (32 bit integer) the specified base to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inlineinherited |
Print using printf-style formatting to the stream or file.
format | printf-style formatting string |
args | variable arguments |
|
inherited |
Print a double floating point value plus a CRLF end-of-line terminator to the stream or file.
value | The value to print. |
dec | The number of decimal places to include for the fractional part. Default: 2 |
|
inherited |
Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or file.
value | The value to print |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the stream or file.
value | The value to print |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print an unsigned char (byte value. 8 bits) in the specified base plus a CRLF end-of-line terminator to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file.
value | The value to print |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inherited |
Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file.
value | The value to print. |
base | The base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary). |
|
inlineinherited |
Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file.
format | printf-style formatting string |
args | variable arguments |
void IsolatedEthernet::TCPServer::stop | ( | ) |
Stop accepting connections.
This method only closes the most recent client connection to the server. If you have multiple connections open, only the last is closed. This makes no sense, but that's how the Device OS TCPServer works.
|
virtual |
Writes a buffer of data to the remote host. Do not use this method!
buf | Pointer to a buffer of bytes to send (can be binary or ASCII) |
size | Number of bytes to send. |
Do not use this method. Instead store the TCPClient object that is returned from server.available() and use that.
If you use this method, and a new connection comes in on the same port, you will start communicating with that client and no longer be able to communicate with the original one, which makes no sense, but this is how the Device OS TCPServer Wiring API works.
Reimplemented from Print.
|
virtual |
Writes a buffer of data to the remote host. Do not use this method!
buf | 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 |
Do not use this method. Instead store the TCPClient object that is returned from server.available() and use that.
If you use this method, and a new connection comes in on the same port, you will start communicating with that client and no longer be able to communicate with the original one, which makes no sense, but this is how the Device OS TCPServer Wiring API works.
|
virtual |
Writes a single byte to most recently connected remote host. Do not use this method!
b | The byte to write (can be ASCII or binary). |
Do not use this method. Instead store the TCPClient object that is returned from server.available() and use that.
If you use this method, and a new connection comes in on the same port, you will start communicating with that client and no longer be able to communicate with the original one, which makes no sense, but this is how the Device OS TCPServer Wiring API works.
Implements Print.
|
virtual |
Writes a single byte to the remote host. Do not use this method!
b | The byte to write (can be ASCII or binary). |
timeout | Timeout in milliseconds, or 0 to wait forever |
Do not use this method. Instead store the TCPClient object that is returned from server.available() and use that.
If you use this method, and a new connection comes in on the same port, you will start communicating with that client and no longer be able to communicate with the original one, which makes no sense, but this is how the Device OS TCPServer Wiring API works.