Hauptseite | Klassenhierarchie | Alphabetische Liste | Auflistung der Klassen | Auflistung der Dateien | Klassen-Elemente

# TCPIPCommConnect.h

    00001 //*****************************************************************************
    00002 // project   : ANALYTICA Class Library
    00003 // part      : Communication class for simple TCP/IP
    00004 // file name : TCPIPCommConnect.h
    00005 // version   : $revision:$
    00006 // author    : Udo Weber
    00007 // platform  : MS VC++ 6.0
    00008 //
    00009 //-----------------------------------------------------------------------------
    00010 // Description:
    00011 // =============
    00012 // implementation of the class CTCPIPComm to encapsulate simple TCP/IP
    00013 // communications
    00014 // Part : Connection establishment
    00015 //
    00016 //-----------------------------------------------------------------------------
    00017 // Revisionhistory:
    00018 // $Log: TCPIPCommConnect.h,v $
    00019 // Revision 1.4  2001/08/23 11:21:33  AxelSchmidt
    00020 // neue Funktion ConvToInAddr(
    00021 //
    00022 // Revision 1.3  2001/08/21 06:51:17  AxelSchmidt
    00023 // Zugriffsfunktion auf native Remotepartner hinzugefuegt
    00024 //
    00025 // Revision 1.2  2001/07/12 14:35:59  AxelSchmidt
    00026 // virtuelle Basis-Klasse CTraceObject hinzugefügt
    00027 //
    00028 // 20.07.1998 UWe  Some bug fixes
    00029 // 20.04.1998 UWe  first version
    00030 //*****************************************************************************
    00031
    00032 #ifndef _TCPIPCommConnect_h
    00033 #define _TCPIPCommConnect_h
    00034
    00035 //---- includes ---------------------------------------------------------------
    00036
    00037 #include <winsock.h>
    00038 #include "TraceObject.h"
    00039
    00040
    00041 //---- defines/const ----------------------------------------------------------
    00042
    00043
    00044 //---- enums ------------------------------------------------------------------
    00045
    00046
    00047 //---- structs ----------------------------------------------------------------
    00048
    00049
    00050 //---- classes ----------------------------------------------------------------
    00051
    00057 class CTCPIPCommConnect : virtual public CTraceObject
    00058 {
    00059    // public part
    00060 public:
    00061
    00067    CTCPIPCommConnect();
    00068
    00070    virtual ~CTCPIPCommConnect();
    00071
    00072
    00073    //
    00074    // public operations
    00075    //
    00076
    00084    void Initialize( const short        TCPport,
    00085                     const char         *pIPAddress,
    00086                     const bool         PassiveConnection = false );
    00087
    00093    bool ConnectRequest( SOCKET   PassiveSocket );
    00094
    00095
    00101    bool DisconnectRequest( void );
    00102
    00103
    00109    int GetLastSocketError( void ) const;
    00110
    00116    bool Terminating( void ) const;
    00117
    00123    SOCKET GetSocket( void );
    00124
    00130    unsigned long GetRemoteIPAddr   ( void );
    00131
    00137    struct in_addr ConvToInAddr( unsigned long nIPAddress ) const;
    00138
    00142    const SOCKADDR_IN & GetRemoteAddr( void );
    00143
    00150    SOCKADDR_IN ConvTCPAddrToSocketAddr( const short   TCPport,
    00151                                         const char    *pIPAddr );
    00152
    00153
    00154    // protected part
    00155 protected:
    00156
    00157    //
    00158    // virtual callback functions
    00159    //
    00160
    00166    virtual void ConInd( void ) = 0;
    00167
    00173    virtual void DisInd( void ) = 0;
    00174
    00175
    00176
    00177    // private part
    00178 private:
    00179
    00186    bool AwaitConnection( void );
    00187
    00194    bool EstablishConnection( void );
    00195
    00196
    00197    //
    00198    // static member functions
    00199    //
    00205    static void ConnectThread( CTCPIPCommConnect *pClass );
    00206
    00207
    00208
    00209    // member definition
    00210    SOCKET          m_Socket;
    00211    SOCKET          m_PassiveSocket;
    00212    SOCKADDR_IN     m_RemoteAddr;
    00213    bool            m_PassiveConnection;
    00214    int             m_LastSocketError;
    00215
    00216    DWORD           m_ThreadID;
    00217
    00218    HANDLE          m_ThreadHandle;
    00219    HANDLE          m_hEventTerminate;
    00220    HANDLE          m_hEventTerminateFinished;
    00221    HANDLE          m_hEventConnecting;
    00222
    00223    unsigned long   m_RemoteIPAddr;
    00224
    00225    bool            m_Terminating;
    00226 };
    00227
    00228
    00229 //
    00230 // inline operations
    00231 //
    00232
    00233 // get last socket error
    00234 inline int CTCPIPCommConnect::GetLastSocketError( void ) const
    00235 {
    00236    return m_LastSocketError;
    00237 }
    00238
    00239
    00240 inline bool CTCPIPCommConnect::Terminating( void ) const
    00241 {
    00242    return m_Terminating;
    00243 }
    00244
    00245
    00246 // get socket of established connection
    00247 inline SOCKET CTCPIPCommConnect::GetSocket( void )
    00248 {
    00249    return m_Socket;
    00250 }
    00251
    00252
    00253 // get IP Address of connected (remmote) partner
    00254 inline unsigned long CTCPIPCommConnect::GetRemoteIPAddr( void )
    00255 {
    00256    return m_RemoteIPAddr;
    00257 }
    00258
    00259 inline  const SOCKADDR_IN & CTCPIPCommConnect::GetRemoteAddr( void )
    00260 {
    00261    return m_RemoteAddr;
    00262 }
    00263
    00264
    00265 #endif // _TCPIPCommConnect_h