#ifndef Client_H #define Client_H #include #include "Network.h" #ifdef INCLUDE_SSL # include # include #else struct SSL_CTX; struct SSL; struct BIO; #endif namespace Framework { namespace Encryption { class Key; } class Text; } // namespace Framework using namespace Framework; namespace Network { class Client; // from this file class Client : public EncryptedConnection, public virtual ReferenceCounter { private: SOCKET sock; sockaddr_in server; Encryption::Key* sendKey; Encryption::Key* receiveKey; int downStreamBytes; int upStreamBytes; bool errorOccured; public: // Constructor __declspec(dllexport) Client(); // Destructor __declspec(dllexport) ~Client(); // non-constant __declspec(dllexport) void setSendKeyZ( Encryption::Key* key); // Sets the key for sending __declspec(dllexport) void setReceiveKeyZ( Encryption::Key* key); // Sets the key for receiving __declspec(dllexport) void setSendKey( const char* key, int len); // Sets the key for sending __declspec(dllexport) void setReceiveKey( const char* key, int len); // Sets the key for receiving __declspec(dllexport) bool connect( unsigned short port, const char* ip); // connects to server __declspec(dllexport) bool send( const char* message, int len) override; // sends to server __declspec(dllexport) bool getMessage( char* message, int len) override; // receives message __declspec(dllexport) bool sendEncrypted( const char* message, int len) override; // sends to server __declspec(dllexport) bool getMessageEncrypted( char* message, int len) override; // receives message __declspec(dllexport) int getDownloadBytes( bool reset); // returns the number of received bytes __declspec(dllexport) int getUploadBytes( bool reset); // returns the number of sent bytes __declspec(dllexport) bool disconnect(); // Disconnects from server // constant __declspec(dllexport) bool hasMessage( int time); // Waits for a message for a given time __declspec(dllexport) unsigned short getServerPort() const; // returns the server port __declspec(dllexport) const char* getServerIp() const; // returns the server IP __declspec(dllexport) bool waitForNextMessage() const; // waits until there is something to receive __declspec(dllexport) bool isConnected() const; // returns true if a connection exists }; class SSLClient : public Connection, public virtual ReferenceCounter { private: unsigned short port; Text* ip; SSL_CTX* ctx; SSL* ssl; BIO* bio; int downStreamBytes; int upStreamBytes; bool connected; public: // Constructor __declspec(dllexport) SSLClient(); // Destructor __declspec(dllexport) ~SSLClient(); __declspec(dllexport) bool connect( unsigned short port, const char* ip); // connects to server __declspec(dllexport) bool send( const char* message, int len) override; // sends to server __declspec(dllexport) bool getMessage( char* message, int len) override; // receives message __declspec(dllexport) int getDownloadBytes( bool reset); // returns the number of received bytes __declspec(dllexport) int getUploadBytes( bool reset); // returns the number of sent bytes __declspec(dllexport) bool disconnect(); // Disconnects from server // constant __declspec(dllexport) bool hasMessage( int time); // Waits for a message for a given time __declspec(dllexport) unsigned short getServerPort() const; // returns the server port __declspec(dllexport) const char* getServerIp() const; // returns the server IP }; } // namespace Network #endif