friendev EtherDune TCP/IP library
|
Maintains a list of available sockets, also listening and spawning sockets to serve multiple clients simultaneously. More...
#include <TCPListener.h>
Public Member Functions | |
void | listen (uint16_t port) |
Starts to listen on the specified TCP port. More... | |
![]() | |
TCPSocket () | |
void | connect () |
Initiates a TCP connection to remoteIP and remotePort. More... | |
void | close () |
Attempts to gracefully close a connection. More... | |
void | terminate () |
Immediately shuts down the socket and makes it available for a new task. More... | |
void | listen () |
Starts listening on the local port indicated by the localPort property. More... | |
void | accept () |
Accepts a connection request that has been received on the port this instance was listening on More... | |
void | accept (TCPSocket &listener) |
Accepts a connection request that was sent to another TCPSocket instance. More... | |
void | push () |
Sets the PSH TCP flag and also sends data in the outgoing buffer immediately. More... | |
virtual void | onConnect () |
Fires when the socket connection is established. More... | |
virtual void | onClose () |
Fires when the other party closed the incoming end of the connection because it has no more data to send. More... | |
virtual void | onReceive (uint16_t len, const byte *data) |
Called for each data packet received More... | |
![]() | |
uint16_t | write (uint16_t len, const byte *data) |
In the case of TCP, writes the given data buffer to the socket. More... | |
uint16_t | write (const String &s) |
In the case of TCP, writes the given String to the socket, not including the null-terminating character. More... | |
uint16_t | write (const __FlashStringHelper *pattern,...) |
Writes out the specified PROGMEM string that may contain the % escape character. More... | |
template<class T > | |
uint16_t | write (const T &message) |
Writes out the binary representation of the parameter to the socket. More... | |
![]() | |
uint8_t | getState () |
Protected Member Functions | |
virtual void | onNoMoreConnections () |
Called when there are no more sockets available More... | |
void | onTerminate () |
Called when the socket is ready to be reused. More... | |
void | onConnectRequest () |
Called when a listening socket receives a connection request. More... | |
![]() | |
void | prepareIPPacket () |
![]() | |
NetworkService () | |
~NetworkService () | |
virtual void | onDNSResolve (uint8_t status, uint16_t identification, const IPAddress &ip) |
Called on each network service every time a DNS response is received. More... | |
![]() | |
void | setState (uint8_t newState, uint8_t timeout) |
Changes to a new state More... | |
Protected Attributes | |
SOCKET | clients [MAX_CLIENTS] |
![]() | |
SharedBuffer | buffer |
output buffer for this socket More... | |
![]() | |
uint8_t | stateTimer |
state timer, in ticks More... | |
uint8_t | state |
state code More... | |
Additional Inherited Members | |
![]() | |
nint16_t | remotePort |
remote TCP or UDP port More... | |
nint16_t | localPort |
local TCP or UDP port More... | |
IPAddress | remoteIP |
remote IP address to connect to (TCP) or send the next packet to (UDP) More... | |
![]() | |
static uint16_t | calcPseudoHeaderChecksum (uint8_t protocol, uint16_t length) |
Calculates the TCP or UDP pseudo header checksum. More... | |
static uint16_t | calcTCPChecksum (bool options, uint16_t dataLength, uint16_t dataChecksum) |
Calculates the TCP checksum. More... | |
static uint16_t | calcUDPChecksum (uint16_t dataLength, uint16_t dataChecksum) |
Calculates the UDP checksum. More... | |
static bool | verifyUDPTCPChecksum () |
Verifies if the UDP or TCP checksum of the current packet is correct. More... | |
![]() | |
static bool | sendIPPacket (uint16_t length) |
Puts the current in-memory packet in the network More... | |
static void | prepareIPPacket (const IPAddress &remoteIP) |
Sets up common IP header values for all outgoing IP packets and calculates the IP header checksum More... | |
static bool | sameLAN (IPAddress &dst) |
Determines whether the given IP is in the same subnet as localIP More... | |
static bool | begin (uint8_t cspin) |
Initializes EtherDune and the underlying hardware More... | |
static void | loop () |
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets. More... | |
static DNSClient & | DNS () |
Obtains access to the DNS service singleton instance. More... | |
![]() | |
static void | writeByte (byte b) |
static void | writeByte (uint16_t dst, byte b) |
static void | writeBuf (uint16_t dst, uint16_t len, const byte *data) |
static void | writeBuf (uint16_t len, const byte *data) |
static uint16_t | hardwareChecksum (uint16_t src, uint16_t len) |
static uint16_t | hardwareChecksumRxOffset (uint16_t offset, uint16_t len) |
static void | moveMem (uint16_t dest, uint16_t src, uint16_t len) |
static void | readBuf (uint16_t src, uint16_t len, byte *data) |
static void | readBuf (uint16_t len, byte *data) |
static byte | readByte (uint16_t src) |
static void | packetSend (uint16_t len) |
static void | packetSend (uint16_t len, const byte *data) |
static void | loadSample () |
static void | loadAll () |
static void | release () |
static uint8_t | begin (uint8_t cspin) |
static void | loop () |
static void | enableBroadcast () |
static bool | isLinkUp () |
Determines whether the network link is ready More... | |
![]() | |
static uint8_t | srcPort_L_count = 0 |
self-incrementing counter for local ports. More... | |
![]() | |
static EthBuffer | packet |
in-memory packet buffer currently being processed. More... | |
static ARPService | ARP |
ARP singleton instance. More... | |
static MACAddress | localMAC |
Ethernet MAC address. More... | |
static IPAddress | localIP = { 0, 0, 0, 0 } |
IP address of this application. More... | |
static IPAddress | gatewayIP = { 0, 0, 0, 0 } |
IP address of the gateway in this network. More... | |
static IPAddress | netmask = { 0, 0, 0, 0 } |
Subnet mask. More... | |
static IPAddress | dnsIP = { 0, 0, 0, 0 } |
IP address of the DNS server to use. More... | |
Maintains a list of available sockets, also listening and spawning sockets to serve multiple clients simultaneously.
This class starts a listening socket that accepts all connection requests and tries to assign the workload of serving each request to an available socket.
The template takes two parameters:
SOCKET: a type that is expected to derive from TCPSocket MAX_CLIENTS: maximum number of simultaneous connections to accomodate. TCPListener will statically allocate an array of MAX_CLIENT instances of SOCKET, so size MAX_CLIENTS carefully.
Each time a new connection is established, onConnect() will be called on the corresponding SOCKET instance.
See HTTPServerDemo_MultipleClients.ino for a working example. Compare with HTTPServerDemo.ino to see the difference
Definition at line 45 of file TCPListener.h.
|
inline |
Starts to listen on the specified TCP port.
port | The port to listen on |
Definition at line 83 of file TCPListener.h.
|
inlineprotectedvirtual |
Called when a listening socket receives a connection request.
To accept the connection request, call accept()
Reimplemented from TCPSocket.
Definition at line 60 of file TCPListener.h.
|
inlineprotectedvirtual |
Called when there are no more sockets available
Definition at line 52 of file TCPListener.h.
|
inlineprotectedvirtual |
Called when the socket is ready to be reused.
Reimplemented from TCPSocket.
Definition at line 56 of file TCPListener.h.
|
protected |
Definition at line 48 of file TCPListener.h.