S60 3rd Edition SDK for Symbian OS
Example Applications Guide

ChatInet.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : ChatInet.h
00004 *  Part of     : Chat
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef CHATINET_H
00017 #define CHATINET_H
00018 
00019 #include <es_sock.h>
00020 #include <in_sock.h>
00021 #include "ChatBase.h"
00022 
00023 // CONSTANTS
00024 const TInt KIpAddressLen = 15;
00025 
00026 // FORWARD DECLARATIONS
00027 class MLog;
00028 
00029 /**
00030 * CChatInet
00031 * Connects and sends messages to a remote machine using bluetooth
00032 */
00033 class CChatInet : public CChatBase
00034     {
00035     public: // Constructors and destructor
00036 
00037         /**
00038         * NewL
00039         * Construct a CChatInet
00040         * @param aLog the log to send output to
00041         * @return a pointer to the created instance of CChatInet
00042         */
00043         static CChatInet* NewL( MLog& aLog );
00044 
00045         /**
00046         * NewLC
00047         * Construct a CChatInet
00048         * @param aLog the log to send output to
00049         * @return a pointer to the created instance of CChatInet
00050         */
00051         static CChatInet* NewLC( MLog& aLog );
00052 
00053         /**
00054         * ~CChatInet
00055         * Destroy the object and release all memory objects. 
00056         * Close any open sockets.
00057         */
00058         virtual ~CChatInet();
00059 
00060     public:     // New functions
00061 
00062         /**
00063         * ConnectL
00064         * Connect to an available service on a remote machine
00065         */
00066         void ConnectL( const TDesC& aAddress );
00067 
00068         /** 
00069         * DisconnectL
00070         * Disconnect from remote machine
00071         */
00072         void DisconnectL();
00073 
00074         /**
00075         * SendMessageL
00076         * Sends a message to a service on a remote machine.
00077         */    
00078         void SendMessageL( const TDesC& aText );
00079         
00080         /**
00081         * Stop
00082         * Stop server.
00083         */  
00084         void Stop();
00085         
00086         /**
00087         * RequestData()
00088         * Read more data from socket.
00089         */  
00090         void RequestData();
00091     
00092         /**
00093         * StartL
00094         * Start server.
00095         */ 
00096         void StartL();
00097     
00098     private:  // New functions
00099         /**
00100         * ConnectL
00101         * Connect to server.
00102         * @param aAddr address to connect to
00103         */ 
00104         void ConnectL( TUint32 aAddr );
00105     
00106     protected:    // from CActive
00107 
00108         /**
00109         * DoCancel
00110         * Cancel any outstanding requests
00111         */
00112         void DoCancel();
00113 
00114         /**
00115         * RunL
00116         * Respond to an event
00117         */
00118         void RunL();
00119 
00120     private:    // Functions from base classes
00121     
00122         /**
00123         * ConnectToServerL
00124         * Connects to the service
00125         */    
00126         void ConnectToServerL( const TDesC& aAddress );
00127 
00128         /**
00129         * DisonnectFromServerL
00130         * Disconnects from the service
00131         */    
00132         void DisconnectFromServerL();
00133 
00134         /**
00135         * CChatInet
00136         * Constructs this object
00137         */
00138         CChatInet( MLog& aLog );
00139 
00140         /**
00141         * ConstructL
00142         * Performs second phase construction of this object
00143         */
00144         void ConstructL();
00145 
00146     private:    // data
00147     
00148         /** 
00149         * iLog 
00150         * the log to send output to 
00151         */
00152         MLog& iLog;
00153 
00154         /** 
00155         * iMessage a copy of the message to send 
00156         * Owned by CChatInet
00157         */
00158         HBufC8* iMessage;
00159 
00160         /** 
00161         * iConnection 
00162         * a management interface to network connection 
00163         */
00164         RConnection iConnection;
00165     
00166         /** 
00167         * iSocketServer
00168         * a connection to the socket server 
00169         */
00170         RSocketServ iSocketServer;
00171 
00172         /** 
00173         * iSendingSocket
00174         * a socket to connect with 
00175         */
00176         RSocket iSocket;
00177 
00178         /** 
00179         * iBuffer
00180         * the buffer to read data to 
00181         */
00182         TBuf8<KChatTextBufLength> iBuffer;
00183         
00184         /**
00185         * iAddress
00186         * the address to be used in the connection.
00187         */
00188         TInetAddr iAddress;
00189 
00190         /**
00191         * iPort
00192         * the port number to connect to.
00193         */
00194         TInt iPort;
00195 
00196         /** 
00197         * iAcceptedSocket
00198         * the socket that connections are accepted to 
00199         */
00200         RSocket iAcceptedSocket;
00201     
00202         /** 
00203         * iLen
00204         * length of data read 
00205         */
00206         TSockXfrLength iLen;
00207 
00208         /**
00209         * iResolver
00210         * DNS name resolver.
00211         */
00212         RHostResolver iResolver;
00213 
00214         /**
00215         * iNameEntry
00216         * the result from the name resolver.
00217         */
00218         TNameEntry iNameEntry;
00219 
00220         /**
00221         * iNameRecord
00222         * the name record found by the resolver.
00223         */
00224         TNameRecord iNameRecord;
00225         
00226         /**
00227         * iActiveSocket
00228         * the active socket 
00229         */
00230         RSocket* iActiveSocket;
00231 
00232     };
00233 
00234 #endif // CHATINET_H
00235 
00236 // End of File

© Nokia 2006

Back to top