IsolatedEthernet
Public Member Functions
IsolatedEthernet::TCPServer Class Reference

Replacement for TCPServer class to use Ethernet. More...

#include <IsolatedEthernet.h>

Inheritance diagram for IsolatedEthernet::TCPServer:
Print

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...
 

Detailed Description

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.).

Constructor & Destructor Documentation

◆ TCPServer()

IsolatedEthernet::TCPServer::TCPServer ( uint16_t  port,
network_interface_t  nif = 0 
)

Construct a new TCPServer object. This is safe as a globally constructed object.

Parameters
portThe port number to bind to, or 0 for any available port.
nifIgnored

◆ ~TCPServer()

IsolatedEthernet::TCPServer::~TCPServer ( )
inline

Destroy the TCPServer object, free the underlying listening socket.

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.

Member Function Documentation

◆ available()

IsolatedEthernet::TCPClient IsolatedEthernet::TCPServer::available ( )

If a connection has been made to this server, returns it.

Returns
IsolatedEthernet::TCPClient The TCPClient that will be used to handle the new connection

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.

◆ begin()

virtual bool IsolatedEthernet::TCPServer::begin ( )
virtual

Starts a server listening for a connection.

Returns
true
false

This should only be done after IsolatedEthernet().instance().ready() is true (the PHY link is up and the device has an IP address.)

◆ print() [1/6]

size_t Print::print ( double  value,
int  dec = 2 
)
inherited

Print a double floating point value to the stream or file.

Parameters
valueThe value to print.
decThe number of decimal places to include for the fractional part. Default: 2

◆ print() [2/6]

size_t Print::print ( int  value,
int  base = DEC 
)
inherited

Print an int (32 bit integer) the specified base to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ print() [3/6]

size_t Print::print ( long  value,
int  base = DEC 
)
inherited

Print a long (32 bit integer) the specified base to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ print() [4/6]

size_t Print::print ( unsigned char  value,
int  base = DEC 
)
inherited

Print an unsigned char (byte value, 8 bits) in the specified base to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ print() [5/6]

size_t Print::print ( unsigned int  value,
int  base = DEC 
)
inherited

Print an unsigned int (32 bit unsigned integer) the specified base to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ print() [6/6]

size_t Print::print ( unsigned long  value,
int  base = DEC 
)
inherited

Print a unsigned long (32 bit unsigned integer) the specified base to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ printf()

template<typename... Args>
size_t Print::printf ( const char *  format,
Args...  args 
)
inlineinherited

Print using printf-style formatting to the stream or file.

Parameters
formatprintf-style formatting string
argsvariable arguments

◆ println() [1/6]

size_t Print::println ( double  value,
int  dec = 2 
)
inherited

Print a double floating point value plus a CRLF end-of-line terminator to the stream or file.

Parameters
valueThe value to print.
decThe number of decimal places to include for the fractional part. Default: 2

◆ println() [2/6]

size_t Print::println ( int  value,
int  base = DEC 
)
inherited

Print an int (32 bit integer) the specified base to plus a CRLF end-of-line terminator the stream or file.

Parameters
valueThe value to print
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ println() [3/6]

size_t Print::println ( long  value,
int  base = DEC 
)
inherited

Print a long (32 bit signed integer) the specified base plus a CRLF end-of-line terminator to the stream or file.

Parameters
valueThe value to print
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ println() [4/6]

size_t Print::println ( unsigned char  value,
int  base = DEC 
)
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.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ println() [5/6]

size_t Print::println ( unsigned int  value,
int  base = DEC 
)
inherited

Print an unsigned int (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file.

Parameters
valueThe value to print
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ println() [6/6]

size_t Print::println ( unsigned long  value,
int  base = DEC 
)
inherited

Print a unsigned long (32 bit unsigned integer) the specified base plus a CRLF end-of-line terminator to the stream or file.

Parameters
valueThe value to print.
baseThe base to print. Default is DEC (decimal). Other values are HEX (hexadecimal), OCT (octal), and BIN (binary).

◆ printlnf()

template<typename... Args>
size_t Print::printlnf ( const char *  format,
Args...  args 
)
inlineinherited

Print using printf-style formatting plus a CRLF end-of-line terminator to the stream or file.

Parameters
formatprintf-style formatting string
argsvariable arguments

◆ stop()

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.

◆ write() [1/4]

virtual size_t IsolatedEthernet::TCPServer::write ( const uint8_t *  buf,
size_t  size 
)
virtual

Writes a buffer of data to the remote host. Do not use this method!

Parameters
bufPointer to a buffer of bytes to send (can be binary or ASCII)
sizeNumber of bytes to send.
Returns
size_t The number of bytes written, typically 1.

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.

◆ write() [2/4]

virtual size_t IsolatedEthernet::TCPServer::write ( const uint8_t *  buf,
size_t  size,
system_tick_t  timeout 
)
virtual

Writes a buffer of data to the remote host. Do not use this method!

Parameters
bufPointer to a buffer of bytes to send (can be binary or ASCII)
sizeNumber of bytes to send.
timeoutTimeout in milliseconds, or 0 to wait forever
Returns
size_t The number of bytes written, typically 1.

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.

◆ write() [3/4]

virtual size_t IsolatedEthernet::TCPServer::write ( uint8_t  b)
virtual

Writes a single byte to most recently connected remote host. Do not use this method!

Parameters
bThe byte to write (can be ASCII or binary).
Returns
size_t The number of bytes written, typically 1.

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.

◆ write() [4/4]

virtual size_t IsolatedEthernet::TCPServer::write ( uint8_t  b,
system_tick_t  timeout 
)
virtual

Writes a single byte to the remote host. Do not use this method!

Parameters
bThe byte to write (can be ASCII or binary).
timeoutTimeout in milliseconds, or 0 to wait forever
Returns
size_t The number of bytes written, typically 1.

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.


The documentation for this class was generated from the following file: