00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#ifndef _TCPIPComm_h
00026
#define _TCPIPComm_h
00027
00028
00029
00030
#include <winsock.h>
00031
00032
#include "TCPIPCommConnect.h"
00033
#include "TCPIPCommSend.h"
00034
#include "TCPIPCommReceive.h"
00035
00036
00037
00038
00039
#define MAX_DIF_ADDR 5 // Maximum of different local address
00040
00041
00042
00043
00044
00045
00046
00047
00048
00054 class CTCPIPComm :
public CTCPIPCommReceive,
00055
public CTCPIPCommSend,
00056
public CTCPIPCommConnect
00057 {
00058
00059
public:
00060
00070
CTCPIPComm(
const short TCPport,
00071
const char *pIPAddress,
00072
const bool PassiveConnection,
00073
const long MaxSendDataLen,
00074
const long MaxRecvDataLen );
00075
00077
virtual ~CTCPIPComm();
00078
00079
00080
00081
00082
00083
00089
int GetLastSocketError(
void )
const;
00090
00091
00097
bool IsConnected(
void )
const;
00098
00105
bool ConnectRequest(
void );
00106
00107
00114
bool Send(
const void *pData,
00115
const long DataLen );
00116
00117
00118
00119
00120
protected:
00121
00122
00123
00124
00125
00131
virtual void ConnectIndication(
void ) = 0;
00132
00138
virtual void DisconnectIndication(
void ) = 0;
00139
00142
CTCPIPComm(
void );
00143
00153
void Initialize(
const short TCPport,
00154
const char *pIPAddress,
00155
const bool PassiveConnection,
00156
const long MaxSendDataLen,
00157
const long MaxRecvDataLen );
00158
00159
00160
private:
00161
00167
void ConInd(
void );
00168
00174
void DisInd(
void );
00175
00181
void RecvDisInd(
void );
00182
00188
void SendDisInd(
void );
00189
00190
00191
00192
00193
int m_LastSocketError;
00194
bool m_PassiveConnection;
00195
bool m_LineConnected;
00196 SOCKADDR_IN m_RemoteAddr;
00197 SOCKET m_PassiveSocket;
00198
00199
bool m_bInitialized;
00200
00201
bool m_bTerminating;
00202
00203
static int m_NumOfInstances;
00204
00205
static bool m_bArrayUsed[MAX_DIF_ADDR];
00206
static SOCKADDR_IN m_ArrayRemoteAddr[MAX_DIF_ADDR];
00207
static SOCKET m_ArrayPassiveSocket[MAX_DIF_ADDR];
00208 };
00209
00210
00211
00212
00213
00214
00215
00216 inline int CTCPIPComm::GetLastSocketError(
void )
const
00217
{
00218
return m_LastSocketError;
00219 }
00220
00221
00222 inline bool CTCPIPComm::IsConnected(
void )
const
00223
{
00224
return m_LineConnected;
00225 }
00226
00227
00228
00229
#endif // _TCPIPComm_h