Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/TCPEndpoint.h

Go to the documentation of this file.
00001 /** 
00002 * @file  Platform/Aperios1.3.2/TCPEndpoint.h
00003 *
00004 * @author <A href=mailto:robocup@m-wachter.de>Michael Wachter</A>
00005 */
00006 
00007 #ifndef _TCPEndpoint_H_
00008 #define _TCPEndpoint_H_
00009 
00010 #include "IPEndpoint.h"
00011 #include <TCPEndpointMsg.h>
00012 
00013 /**
00014  * handels a TCP-Connection 
00015  */
00016      
00017 class TCPEndpoint : public IPEndpoint
00018 {
00019     public:
00020        enum statusID
00021        {
00022          closed,
00023          connecting,
00024          connected,
00025          listening,
00026          sending,
00027          receiving,
00028          closing
00029        }; /**< current State of the TCP-connection */
00030 
00031        TCPEndpoint(int sendBufferSize = 8192, int receiveBufferSize = 8192); /**< constructor with standard buffer size of 8192 bytes */
00032        TCPEndpoint(char* address,int port);   /**< constructor which opens a connection to address:port **/
00033        ~TCPEndpoint();
00034 
00035        int listen(int port);                   /**< listens for incomming connection. onConnect is called if the connection is established */
00036        int connect(char* address, int port);   /**< connects to another host */
00037        int send(void* Data,int size);          /**< sends data (data should not be changed until onSendingDone is called)
00038                               if the data is bigger than sendBufferSize its splittet up and after all data 
00039                           is send onSendingDone is called */
00040        int close();                            /**< close the connection */
00041               
00042        virtual void onConnect(void);           /**< called by the framwork if the connection is established */
00043        virtual void onReceive(void* Data,int size);  /**< called when data is received */
00044        virtual void onClose(int reason);      /**< called when the connection ist closed by the other host */
00045        virtual void onSendingDone(void);      /**< called after all data from send() ist successfully send */
00046              
00047        const char* getErrorString(TCPEndpointError error); /**< gets a cleartext error string */
00048                  
00049        virtual void listenCont(antEnvMsg* msg);  
00050        virtual void sendCont(antEnvMsg* msg);
00051        virtual void receiveCont(antEnvMsg* msg);
00052        virtual void closeCont(antEnvMsg* msg);
00053        virtual void connectCont(antEnvMsg* msg);
00054  
00055        statusID getStatus(void) {return(status);};
00056     
00057     
00058 
00059     protected:
00060        IPAddress address;      /**< IP-address to connect to */
00061        Port port;              /**< Port to connect to */
00062        statusID status;        /**< status of the connection */
00063        void startReceiving();  /**< internal method which calls the ANT-Library to start receiving */
00064        bool wasListening;      /**< if true the socket goes back to listening state after disconnection */
00065        int sizeOfDataToSend;   /**< size of internal send-buffer */
00066        void* sendDataBuffer;   /**< internal send-buffer */
00067 
00068     private:
00069        void sendSendMessage(int size);
00070 
00071 };
00072 
00073 
00074 /**
00075   * Small testing class for TCP-Endpoinr 
00076   */
00077 
00078 class TestServer : public TCPEndpoint
00079 {
00080 
00081 public:
00082 
00083       TestServer():TCPEndpoint(){};
00084       virtual void onConnect(void)
00085       {
00086           char* hello = "I am an AIBO ERS-210 (Wau Wau). Who are you \n";
00087           this->send(hello,strlen(hello)+1);
00088       }
00089 
00090       virtual void onReceive(void* data, int size)
00091       {
00092         char antwort[255];
00093         char* data1 = (char*) data;
00094         data1[size] = 0;
00095         sprintf(antwort,"Hi %s \n",(char*) data1);
00096         
00097         if (data1[0]=='q')
00098         {
00099             close();
00100         }
00101         else
00102         {
00103             this->send(antwort,strlen(antwort));
00104         }
00105         
00106       }
00107 
00108 
00109     
00110 };
00111 
00112 
00113 #endif 
00114 
00115 /*
00116  * Change log :
00117  * 
00118  * $Log: TCPEndpoint.h,v $
00119  * Revision 1.2  2004/09/12 20:10:47  wachter
00120  * Documentation-fixes
00121  *
00122  * Revision 1.1.1.1  2004/05/22 17:23:40  cvsadm
00123  * created new repository GT2004_WM
00124  *
00125  * Revision 1.6  2004/01/26 13:44:07  wachter
00126  * shared-memory-buffers now have variable sizes
00127  *
00128  * Revision 1.5  2004/01/03 16:18:25  wachter
00129  * debug-communication mostly working now
00130  *
00131  * Revision 1.4  2003/12/21 19:27:03  wachter
00132  * Added classes for Sender/Receiver over TCP and UDP.
00133  * ( PLEASE DO NOT USE THIS NOW ! )
00134  *
00135  * Revision 1.3  2003/12/11 15:02:37  wachter
00136  * Low-level TCP and UDP functions for aperios now working.
00137  *
00138  * Revision 1.2  2003/12/03 14:35:51  kindler
00139  * Deleted obsolete UDPConnection
00140  *
00141  * Revision 1.1  2003/12/03 14:21:52  wachter
00142  * Splitted IPEndpoint.*
00143  *
00144  *
00145  */

Generated on Thu Sep 23 19:57:34 2004 for GT2004 by doxygen 1.3.6