mirror of
https://github.com/Show-maket/EthernetMaket.git
synced 2025-06-28 05:09:38 +00:00
server class
This commit is contained in:
@ -1,24 +1,8 @@
|
||||
#ifndef __ETHERNETMAKET_H__
|
||||
#define __ETHERNETMAKET_H__
|
||||
|
||||
#include "Ethernet3.h"
|
||||
|
||||
|
||||
|
||||
enum ConnectionStatusSimple{
|
||||
CONNECT_FAIL = 0,
|
||||
CONNECT_SUCCESS = 1,
|
||||
CONNECT_CONNECTING = 2,
|
||||
CONNECT_START = 3,
|
||||
CONNECT_IDLE = 4,
|
||||
CONNECT_CONNECTED = 5,
|
||||
CONNECT_STOP_START = 6,
|
||||
CONNECT_STOP_WAITING = 7,
|
||||
};
|
||||
|
||||
|
||||
|
||||
#include "EthernetOverride/Server.h"
|
||||
#include "EthernetOverride/TCP.h"
|
||||
|
||||
#include "EthernetOverride/UDP.h"
|
||||
|
||||
#endif // __ETHERNETMAKET_H__
|
@ -61,4 +61,39 @@ void EthernetMaketServer::begin(int sock)
|
||||
listen(sock);
|
||||
EthernetClass::_server_port[sock] = _port;
|
||||
}
|
||||
}
|
||||
|
||||
void EthernetMaketServer::begin()
|
||||
{
|
||||
EthernetServer::begin();
|
||||
}
|
||||
|
||||
void EthernetMaketServer::tick()
|
||||
{
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
||||
{
|
||||
EthernetMaketClient sclient = available(sock);
|
||||
if (sclient.connected() && sclient.available() > 0)
|
||||
{
|
||||
serverHandler(sclient);
|
||||
}
|
||||
// // Закрытие соединения по таймеру неактивности
|
||||
// if (sclient.connected() && (millis() - lastActivityTime > timeout))
|
||||
// {
|
||||
// Serial.println("Connection closed due to inactivity");
|
||||
// sclient.stop();
|
||||
// }
|
||||
|
||||
// if (!wasConnected && sclient.connected())
|
||||
// {
|
||||
// wasConnected[sock] = true;
|
||||
// }
|
||||
|
||||
// if (wasConnected && !sclient.connected())
|
||||
// {
|
||||
// wasConnected[sock] = false;
|
||||
// sclient.stop();
|
||||
// Serial.println("Client disconnected");
|
||||
// }
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
#ifndef __MAKET_SERVER_H__
|
||||
#define __MAKET_SERVER_H__
|
||||
|
||||
#include "Ethernet3.h"
|
||||
#include "../util/config.h"
|
||||
#include "TCP.h"
|
||||
#include <functional>
|
||||
|
||||
class EthernetMaketClient;
|
||||
class EthernetMaketServer : EthernetServer
|
||||
{
|
||||
private:
|
||||
EthernetClient available();
|
||||
void accept(int sock);
|
||||
std::function<void(EthernetMaketClient)> serverHandler = [](EthernetMaketClient sclient){};
|
||||
std::function<void(EthernetMaketClient)> serverHandler = [](EthernetMaketClient sclient) {};
|
||||
bool wasConnected[MAX_SOCK_NUM];
|
||||
|
||||
public:
|
||||
using EthernetServer::EthernetServer;
|
||||
@ -18,7 +19,9 @@ public:
|
||||
|
||||
void setServerHandler(std::function<void(EthernetMaketClient)> handler);
|
||||
void resetServerHandler();
|
||||
void begin() override;
|
||||
void begin(int sock);
|
||||
void tick();
|
||||
};
|
||||
|
||||
#endif // __MAKET_SERVER_H__
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __MAKET_TCP_H__
|
||||
#define __MAKET_TCP_H__
|
||||
|
||||
#include "../EthernetMaket.h"
|
||||
#include "../util/config.h"
|
||||
|
||||
class EthernetMaketClient : public EthernetClient
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __MAKET_UDP_H__
|
||||
#define __MAKET_UDP_H__
|
||||
|
||||
#include "../EthernetMaket.h"
|
||||
#include "../util/config.h"
|
||||
class EthernetMaketUDP : EthernetUDP
|
||||
{
|
||||
private:
|
||||
|
17
src/util/config.h
Normal file
17
src/util/config.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __ETHERNET_MAKET_CONFIG_H__
|
||||
#define __ETHERNET_MAKET_CONFIG_H__
|
||||
|
||||
#include "Ethernet3.h"
|
||||
|
||||
enum ConnectionStatusSimple{
|
||||
CONNECT_FAIL = 0,
|
||||
CONNECT_SUCCESS = 1,
|
||||
CONNECT_CONNECTING = 2,
|
||||
CONNECT_START = 3,
|
||||
CONNECT_IDLE = 4,
|
||||
CONNECT_CONNECTED = 5,
|
||||
CONNECT_STOP_START = 6,
|
||||
CONNECT_STOP_WAITING = 7,
|
||||
};
|
||||
|
||||
#endif // __ETHERNET_MAKET_CONFIG_H__
|
Reference in New Issue
Block a user