message browser to client working

This commit is contained in:
Markus Sattler
2015-05-22 20:35:51 +02:00
parent e7a33beb6e
commit a14a58dbd2
5 changed files with 293 additions and 85 deletions

View File

@ -27,13 +27,67 @@
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <UIPEthernet.h>
#ifndef UIPETHERNET_H
#include <Ethernet.h>
#include <SPI.h>
#endif
#endif
#define DEBUG_WEBSOCKETS(...) Serial1.printf( __VA_ARGS__ ); Serial1.flush()
#ifndef DEBUG_WEBSOCKETS
#define DEBUG_WEBSOCKETS(...)
#endif
#define WEBSOCKETS_MAX_DATA_SIZE (15*1024)
#define WEBSOCKETS_TCP_TIMEOUT (1000)
typedef enum {
WSC_NOT_CONNECTED,
WSC_HEADER,
WSC_CONNECTED
} WSclientsStatus_t;
typedef struct {
uint8_t num; ///< connection number
WSclientsStatus_t status;
#ifdef ESP8266
WiFiClient tcp;
#else
#ifdef UIPETHERNET_H
UIPClient tcp;
#else
EthernetClient tcp;
#endif
#endif
String cUrl; ///< http url
bool cIsUpgrade; ///< Connection == Upgrade
bool cIsWebsocket; ///< Upgrade == websocket
String cKey; ///< client Sec-WebSocket-Key
String cProtocol; ///< client Sec-WebSocket-Protocol
String cExtensions; ///< client Sec-WebSocket-Extensions
int cVersion; ///< client Sec-WebSocket-Version
String sKey; ///< server Sec-WebSocket-Key
} WSclient_t;
class WebSockets {
protected:
void handleWebsocket(WSclient_t * client);
virtual void clientDisconnect(WSclient_t * client);
virtual bool clientIsConnected(WSclient_t * client);
bool readWait(WSclient_t * client, uint8_t *out, size_t n);
};
#endif /* WEBSOCKETS_H_ */