⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpipimpexengine.h

📁 S60下的TCP/IP连接的演示程序
💻 H
字号:
#ifndef __TcpipImpExENGINE_H__
#define __TcpipImpExENGINE_H__

#include <in_sock.h>
#include "TcpipImpExTimer.h"

class CTcpipImpExAppUi;
class CTcpipImpExTimer;


const TInt KMaxServerNameLength = 50;
const TInt KReadBufferSize = 50;
/**
 *
 * @class	CTcpipImpExEngine TcpipImpExEngine.h
 * @brief	Class to make TcpIp connection
 *
 * Copyright (c) EMCC Software Ltd 2003
 * @version	1.0
 *
 */

class CTcpipImpExEngine : public CActive, public MTimeOutNotifier
    {
public:
/*!
  @enum TErrorType

  @discussion Error types encountered when reading/writing to a sockets
  @value EDisconnected A disconnected error has been encountered
  @value ETimeOutOnWrite A write operation has failed to complete within a predetermined period
  @value EGeneralReadError A general error has been encountered during a read
  @value EGeneralWriteError A general error has been encountered during a write
  */
    enum TErrorType
        {
        EDisconnected,
        EGeneralReadError,
		EDNSLookupFailed,
		EConnectionFailed,
		ETimedOut
        };

public: // new methods
/*!
  @function NewL

  @discussion Create a CTcpipImpExEngine object
  @param aAppUi used for ui output
  @result a pointer to the created instance of CTcpipImpExEngine
  */
	static CTcpipImpExEngine* NewL(CTcpipImpExAppUi& aAppUi);

/*!
  @function NewLC

  @discussion Create a CTcpipImpExEngine object
  @param aAppUi used for ui output
  @result a pointer to the created instance of CTcpipImpExEngine
  */
    static CTcpipImpExEngine* NewLC(CTcpipImpExAppUi& aAppUi);

/*!
  @function ~CTcpipImpExEngine

  @discussion Destroy the object and release all memory objects
  */
	~CTcpipImpExEngine();

/*!
  @function ConnectL

  @discussion Initiate connection of socket, using iServerName and iPort
  */
    void ConnectL();

/*!
  @function Disconnect

  @discussion Disconnect socket
  */
    void Disconnect();


public: // from MTimeOutNotifier
/*!
  @function TimerExpired

  @discussion The function to be called when a timeout occurs
  */
	void TimerExpired();

public:
/*!
  @function ReportError

  @discussion Report a communication error
  @param aErrorType error type
  @param aErrorCode associated error code
 */
	void ReportError(TErrorType aErrorType, TInt aErrorCode);


protected: // from CActive
/*!
  @function DoCancel

  @discussion cancel any outstanding operation
  */
	void DoCancel();

/*!
  @function RunL

  @discussion called when operation complete
  */
    void RunL();

private: // New methods
/*!
  @function CTcpipImpExEngine

  @discussion Perform the first phase of two phase construction
  @param aConsole the console to use for ui output
  */
	CTcpipImpExEngine(CTcpipImpExAppUi& aConsole);

/*!
  @function ConstructL

  @discussion Perform the second phase construction of a CTcpipImpExEngine
  */
    void ConstructL();

/*!
  @function ConnectL

  @discussion initiate a connect operation on a socket
  @param aAddr the ip address to connect to
  */
	void ConnectL(TUint32 aAddr);

	void Read();

/*!
  @enum TSocketsEngineState

  @discussion Tracks the state of this object through the connection process
  @value ENotConnected The initial (idle) state
  @value EConnecting A connect request is pending with the socket server
  @value EConnected A connection has been established
  @value ELookingUp A DNS lookup request is pending with the socket server
  */
	enum TEngineState
	    {
		ENotConnected,
        EConnecting,
        EConnected,
		ELookingUp,
		EReading,
		EDestroyed
	    };

/*!
  @function ChangeStatus

  @discussion handle a change in this object's status
  @param aNewStatus new status
  */
    void ChangeStatus(TEngineState aNewStatus);


private: // Member variables

    /*! @var this object's current status */
	TEngineState				iEngineStatus;

    /*! @var console for displaying text etc */
	CTcpipImpExAppUi&			iAppUi;

    /*! @var the actual socket */
	RSocket                     iSocket;

    /*! @var the socket server */
	RSocketServ                 iSocketServ;

    /*! @var DNS name resolver */
	RHostResolver               iResolver;

    /*! @var The result from the name resolver */
	TNameEntry                  iNameEntry;

    /*! @var The anme record found by the resolver */
	TNameRecord                 iNameRecord;

    /*! @var timer active object */
	CTcpipImpExTimer*			iTimer;

    /*! @var The address to be used in the connection */
	TInetAddr                   iAddress;

    /*! @var port number to connect to */
    TInt                        iPort;

    /*! @var server name to connect to */
    TBuf<KMaxServerNameLength>  iServerName;

    /*! @var buffer for receiving data */
	TBuf8<KReadBufferSize>		iBuffer;

    /*! @var dummy - length of data read is written here */
    TSockXfrLength				iLength;


    };

#endif // __TcpipImpExENGINE_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -