mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-16 08:42:06 +02:00
add close #322
This commit is contained in:
@ -29,6 +29,7 @@ WebSocketsServer::WebSocketsServer(uint16_t port, String origin, String protocol
|
||||
_port = port;
|
||||
_origin = origin;
|
||||
_protocol = protocol;
|
||||
_runnning = false;
|
||||
|
||||
_server = new WEBSOCKETS_NETWORK_SERVER_CLASS(port);
|
||||
|
||||
@ -50,15 +51,7 @@ WebSocketsServer::WebSocketsServer(uint16_t port, String origin, String protocol
|
||||
|
||||
WebSocketsServer::~WebSocketsServer() {
|
||||
// disconnect all clients
|
||||
disconnect();
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
|
||||
_server->close();
|
||||
#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||
_server->end();
|
||||
#else
|
||||
// TODO how to close server?
|
||||
#endif
|
||||
close();
|
||||
|
||||
if (_mandatoryHttpHeaders)
|
||||
delete[] _mandatoryHttpHeaders;
|
||||
@ -110,19 +103,36 @@ void WebSocketsServer::begin(void) {
|
||||
randomSeed(millis());
|
||||
#endif
|
||||
|
||||
_runnning = true;
|
||||
_server->begin();
|
||||
|
||||
DEBUG_WEBSOCKETS("[WS-Server] Server Started.\n");
|
||||
}
|
||||
|
||||
void WebSocketsServer::close(void) {
|
||||
_runnning = false;
|
||||
disconnect();
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266)
|
||||
_server->close();
|
||||
#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
||||
_server->end();
|
||||
#else
|
||||
// TODO how to close server?
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||
/**
|
||||
* called in arduino loop
|
||||
*/
|
||||
void WebSocketsServer::loop(void) {
|
||||
if(_runnning) {
|
||||
handleNewClients();
|
||||
handleClientData();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
virtual ~WebSocketsServer(void);
|
||||
|
||||
void begin(void);
|
||||
void close(void);
|
||||
|
||||
#if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||
void loop(void);
|
||||
@ -113,6 +114,8 @@ protected:
|
||||
WebSocketServerEvent _cbEvent;
|
||||
WebSocketServerHttpHeaderValFunc _httpHeaderValidationFunc;
|
||||
|
||||
bool _runnning;
|
||||
|
||||
bool newClient(WEBSOCKETS_NETWORK_CLASS * TCPclient);
|
||||
|
||||
void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin);
|
||||
|
Reference in New Issue
Block a user