-
Notifications
You must be signed in to change notification settings - Fork 109
/
SocketClient.hpp
110 lines (100 loc) · 4.85 KB
/
SocketClient.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef AREG_BASE_SOCKETCLIENT_HPP
#define AREG_BASE_SOCKETCLIENT_HPP
/************************************************************************
* This file is part of the AREG SDK core engine.
* AREG SDK is dual-licensed under Free open source (Apache version 2.0
* License) and Commercial (with various pricing models) licenses, depending
* on the nature of the project (commercial, research, academic or free).
* You should have received a copy of the AREG SDK license description in LICENSE.txt.
* If not, please contact to info[at]aregtech.com
*
* \copyright (c) 2017-2023 Aregtech UG. All rights reserved.
* \file areg/base/SocketClient.hpp
* \ingroup AREG SDK, Automated Real-time Event Grid Software Development Kit
* \author Artak Avetyan
* \brief AREG Platform Client Socket class declaration
************************************************************************/
/************************************************************************
* Include files.
************************************************************************/
#include "areg/base/GEGlobal.h"
#include "areg/base/Socket.hpp"
//////////////////////////////////////////////////////////////////////////
// SocketClient class declaration
//////////////////////////////////////////////////////////////////////////
/**
* \brief The Client Socket is used to connect to remote host server,
* send and receive data. Before sending or receiving any data,
* the socket should be created and as soon as connection is not needed,
* it should be closed.
* Client socket is using only TCP/IP connection. All other types
* and protocols are out of scope of this class and are not considered.
**/
class AREG_API SocketClient : public Socket
{
//////////////////////////////////////////////////////////////////////////
// Constructors / Destructor
//////////////////////////////////////////////////////////////////////////
public:
/**
* \brief Default constructor. Creates instance of object
* with invalid socket object. Before sending
* or receiving data, the socket should be created
* and connected to remote host.
**/
SocketClient( void ) = default;
/**
* \brief Initialization constructor. Creates instance of object
* with invalid socket object. Before sending
* or receiving data, the socket should be created
* and connected to remote host.
* When instantiated, it will resolved passed host
* name and port number. If succeeded to resolve,
* it will set resolved IP-address and port number
* as socket address. If passed hostName is nullptr,
* it resolve connection for local host.
* \param hostName Host name or IP-address of remote server to connect.
* \param portNr Port number of remote server to connect.
**/
SocketClient( const char * hostName, unsigned short portNr );
/**
* \brief Initialization constructor. Creates instance of object
* with invalid socket object. Before sending
* or receiving data, the socket should be created
* and connected to remote host.
* Specified remoteAddress will be set as remote server address to connect.
* \param remoteAddress Address of remote host to connect.
**/
SocketClient( const NESocket::SocketAddress & remoteAddress );
/**
* \brief Destructor.
**/
virtual ~SocketClient( void ) = default;
public:
/************************************************************************/
// Socket overrides
/************************************************************************/
/**
* \brief Before sending or receiving any data from remote host,
* call this method to create new socket descriptor and
* connect to specified remote host and port.
* \param hostName The name of host to connect.
* \param portNr The valid port number to connect.
* \return Returns true if operation succeeded.
**/
virtual bool createSocket( const char * hostName, unsigned short portNr ) override;
/**
* \brief Before sending or receiving any data from remote host,
* call this method to create new socket descriptor and
* connects to existing socket address. The remote host address
* and port number should be already set in socket address.
* \return Returns true if operation succeeded.
**/
virtual bool createSocket( void ) override;
//////////////////////////////////////////////////////////////////////////
// Forbidden calls
//////////////////////////////////////////////////////////////////////////
private:
DECLARE_NOCOPY_NOMOVE( SocketClient );
};
#endif // AREG_BASE_SOCKETCLIENT_HPP