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 /**
00011 * static class for system calls
00012 * @attention the implementation is system specific!
00013 */
00014 
00015 #include "IPEndpoint.h"
00016 #include <TCPEndpointMsg.h>
00017 
00018 /**
00019  * handels a TCP-Connection 
00020  */
00021      
00022 class TCPEndpoint : public IPEndpoint
00023 {
00024     public:
00025        enum statusID
00026        {
00027          closed,
00028          connecting,
00029          connected,
00030          listening,
00031          sending,
00032          receiving,
00033          closing
00034        };
00035 
00036        TCPEndpoint(int sendBufferSize = 8192, int receiveBufferSize = 8192);
00037        TCPEndpoint(char* address,int port);
00038        ~TCPEndpoint();
00039 
00040        int listen(int port);                   /*< listens for incomming connection. onConnect is called if the connection is established */
00041        int connect(char* address, int port);   /*< connects to another host */
00042        int send(void* Data,int size);          /*< sends data (data should not be changed until onSendingDone is called) */
00043        int close();                            /*< close the connection */
00044               
00045        virtual void onConnect(void);
00046        virtual void onReceive(void* Data,int size);  /*< called when data is received */
00047        virtual void onClose(int reason);      /*< called when the connection ist closed by the other host */
00048        virtual void onSendingDone(void);      /*< called after all data from send() ist successfully send */
00049              
00050        const char* getErrorString(TCPEndpointError error);
00051                  
00052        virtual void listenCont(antEnvMsg* msg);
00053        virtual void sendCont(antEnvMsg* msg);
00054        virtual void receiveCont(antEnvMsg* msg);
00055        virtual void closeCont(antEnvMsg* msg);
00056        virtual void connectCont(antEnvMsg* msg);
00057  
00058        statusID getStatus(void) {return(status);};
00059     
00060     
00061 
00062     protected:
00063        IPAddress address;
00064        Port port;
00065        statusID status;
00066        void startReceiving();
00067        bool wasListening;
00068        int sizeOfDataToSend;
00069        void* sendDataBuffer;
00070 
00071     private:
00072        void sendSendMessage(int size);
00073 
00074 };
00075 
00076 
00077 // Class for testing 
00078 
00079 class TestServer : public TCPEndpoint
00080 {
00081 
00082 public:
00083 
00084       TestServer():TCPEndpoint(){};
00085       virtual void onConnect(void)
00086       {
00087           char* hello = "I am an AIBO ERS-210 (Wau Wau). Who are you \n";
00088           this->send(hello,strlen(hello)+1);
00089       }
00090 
00091       virtual void onReceive(void* data, int size)
00092       {
00093         char antwort[255];
00094         char* data1 = (char*) data;
00095         data1[size] = 0;
00096         sprintf(antwort,"Hi %s \n",(char*) data1);
00097         
00098         if (data1[0]=='q')
00099         {
00100             close();
00101         }
00102         else
00103         {
00104             this->send(antwort,strlen(antwort));
00105         }
00106         
00107       }
00108 
00109 
00110     
00111 };
00112 
00113 
00114 #endif 

Generated on Mon Mar 20 22:00:00 2006 for GT2005 by doxygen 1.3.6