Remoto - VFS: VFS_websocket_client.h Source File
Remoto - VFS
VFS_websocket_client.h
Go to the documentation of this file.
1 #ifndef VFS_WEBSOCKET_CLIENT_H
2 #define VFS_WEBSOCKET_CLIENT_H
3 
4 #include <QWebSocket>
5 #include <QHostAddress>
6 
7 #include "VFS_base/VFS_node.h"
8 
10 
12 {
13  Q_OBJECT
14 
15  friend class VFS_websocket_server;
16 
17  public:
18  explicit VFS_websocket_client(QWebSocket *socket, VFS_websocket_server *server);
19  explicit VFS_websocket_client(QString wsurl, quint16 interval=3000);
20  virtual ~VFS_websocket_client();
21 
22  virtual void write(VFS_request *r);
23  virtual void submit(VFS_request *r);
24 
25  virtual bool isContainer();
26  virtual bool isConnecting();
27  virtual bool isConnected();
28 
29  virtual bool writeText(QString data);
30  virtual bool writeBinary(QByteArray data);
31 
32  protected:
33  QWebSocket *_socket;
36  bool _authorized;
37  QHostAddress _address;
38  int _pingID;
39 
40  bool _isClient;
41  int _connectID;
42  QString _wsurl;
43  quint16 _interval;
44 
45  virtual void init();
46  virtual void authorized();
47 
48  virtual QJsonDocument receive(QByteArray message);
49 
50  private:
51 
52  signals:
53  void connected();
54  void disconnected();
55  void readyBinaryMessage(QByteArray message);
56  void readyTextMessage(QString message);
57  void error(QAbstractSocket::SocketError);
58 
59  protected slots:
60  virtual void startPing();
61  virtual void close();
62  virtual void socket_connected();
63  virtual void socket_disconnected();
64  virtual void socket_receive_text(QString message);
65  virtual void socket_receive_binary(QByteArray message);
66  virtual void timerEvent(QTimerEvent *event); //ping here
67 
68 };
69 
70 #endif // VFS_WEBSOCKET_CLIENT_H
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
The base class for all requests between nodes.
Definition: VFS_node.h:54
A VFS_node that manages a QWebSocket connection.
virtual bool isConnecting()
If the client will attempt to reconnect, return true.
bool _isClient
A client connection may not be created by a listening server, thus the second constructor.
virtual void submit(VFS_request *r)
Submit to the socket.
int _pingID
Connections can become stale; This is the ID of the ping timer.
VFS_websocket_client(QWebSocket *socket, VFS_websocket_server *server)
QString _wsurl
For client connections, the WebSocket address to connect to.
QHostAddress _address
The network address of the connected client.
quint16 _interval
The reconnect interval if disconnected.
virtual void authorized()
Notify the node that it has received authorization from some auth method.
void connected()
Connection has been made.
bool _authorized
if this connection has a session
virtual void write(VFS_request *r)
Write to the socket.
virtual void socket_receive_text(QString message)
The socket has received a message in text mode.
void readyTextMessage(QString message)
A text message has been received.
virtual void socket_connected()
Slot called when the client is connected.
int _connectID
For client connections, the reconnect timerID.
virtual void socket_disconnected()
Slot called when the client is disconnected.
virtual ~VFS_websocket_client()
VFS_websocket_client destructor -.
VFS_websocket_server * _server
owning server
virtual void timerEvent(QTimerEvent *event)
Send the ping command.
void readyBinaryMessage(QByteArray message)
A binary message has been received.
bool _authenticated
if auth has taken place and succeeded
virtual void init()
Initialize needed signal/slot connections.
virtual void close()
Close the socket if it is connected.
virtual bool isConnected()
If the client will attempt to reconnect, return true.
virtual bool writeBinary(QByteArray data)
Write binary data over the websocket.
void error(QAbstractSocket::SocketError)
There has been a socket error.
virtual void startPing()
Start the ping timer.
QWebSocket * _socket
client socket
void disconnected()
Connection has been lost.
virtual bool writeText(QString data)
Write text data over the websocket.
virtual void socket_receive_binary(QByteArray message)
VFS_websocket_client::socket_receive_binary.
virtual QJsonDocument receive(QByteArray message)
VFS_websocket_VFSclient::receive.
virtual bool isContainer()
A VFS_websocket_client cannot contain children.
A VFS_websocket server will listen for incoming websocket connections, optionally using ssl.