12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #pragma once
- #include <functional>
- #include <Thread.h>
- #include <Critical.h>
- #include "Klient.h"
- namespace Network
- {
- namespace WebSocket
- {
- struct Frame
- {
- bool fin, rsv1, rsv2, rsv3;
- char opcode;
- bool mask;
- __int64 dataLength;
- unsigned char key[ 4 ];
- char *data;
-
- __declspec( dllexport ) Frame &operator+=( const Frame &b );
- };
- enum DataType
- {
- TEXT,
- BINARY
- };
- class WebSocketClient : public Framework::Thread
- {
- private:
- std::function< void( WebSocketClient *, __int64 size, const char *data, DataType typ ) > callback;
- Klient *klient;
- Framework::Text path;
- Framework::Text host;
- Frame *lastPingFrame;
- Array< Frame > *queue;
- unsigned short port;
- Critical c;
- Critical c2;
- public:
-
-
-
-
- __declspec( dllexport ) WebSocketClient( const char *path, const char *host, unsigned short port );
- __declspec( dllexport ) virtual ~WebSocketClient();
-
- __declspec( dllexport ) void setMessageCallback( std::function< void( WebSocketClient *, __int64 size, const char *data, DataType typ ) > callback );
-
- __declspec( dllexport ) bool connect();
-
-
-
-
- __declspec( dllexport ) bool send( __int64 size, const char *data, DataType typ = TEXT );
-
- __declspec( dllexport ) void thread() override;
-
- __declspec( dllexport ) void disconnect();
-
- __declspec( dllexport ) bool isConnected() const;
- };
- }
- }
|