00001 /** 00002 * @file Platform/Aperios1.3.2/UDPEndpoint.h 00003 * 00004 * @author <A href=mailto:robocup@m-wachter.de>Michael Wachter</A> 00005 */ 00006 00007 #ifndef _UDPEndpoint_H_ 00008 #define _UDPEndpoint_H_ 00009 00010 #include "IPEndpoint.h" 00011 #include <UDPEndpointMsg.h> 00012 00013 /** 00014 * Handles sending and receiving UDP-Packages 00015 */ 00016 00017 class UDPEndpoint : public IPEndpoint 00018 { 00019 public: 00020 UDPEndpoint(int sendBufferSize = 2048, int receiveBufferSize=2048); 00021 00022 ~UDPEndpoint(); 00023 00024 /** binds endpoint to listen to port */ 00025 int bind(int listenPort); 00026 00027 /** binds endpoint to listen to port and sets receiving host 00028 to address:port */ 00029 int bind(int listenPort, char* address, int sendPort); 00030 int bind(Port listenPort, IPAddress address, Port sendPort); 00031 00032 /** sends data from the shared buffer (does no copy of data and assumes that the Data is in sharedSendBuffer */ 00033 int send(int size); 00034 00035 /** sends data from the shared buffer to a givern host/port */ 00036 int send(int size, char* addr, int sPort); 00037 00038 /** sends data to last specified other host (copies the data)*/ 00039 int send(void* data,int size); 00040 00041 /** sends data to other host */ 00042 int send(void* data,int size, char* address,int port); 00043 00044 /** sends data to other host */ 00045 int send(void* data,int size, IPAddress address, int port); 00046 00047 /** Called when new data arrives */ 00048 virtual void onReceive(void* data,int size); 00049 00050 /** Called from close() when connection closes */ 00051 virtual void onClose(); 00052 virtual void onSendingDone(); 00053 00054 /** Closes Endpoint in case of an error */ 00055 void close(); 00056 00057 const char* getErrorString(UDPEndpointError error); /**< gets errorString of error */ 00058 const char* getErrorString(); /**< gets errorString of last error */ 00059 00060 virtual void sendCont(antEnvMsg* msg); /**< called by the framwork is sending is done */ 00061 virtual void receiveCont(antEnvMsg* msg); /**< called by the framweok if there is new data. Actually calls onReceive() */ 00062 virtual void closeCont(antEnvMsg* msg); /**< does cleanup-stuff */ 00063 00064 protected: 00065 IPAddress ipOfLastPackage; /**< Ip of the last package recieved */ 00066 00067 private: 00068 IPAddress address; /**< IP address to send the data to */ 00069 Port sendPort; /**< port to send the data to */ 00070 Port listenPort; /**< port to listen for data */ 00071 void startReceiving(); 00072 00073 }; 00074 00075 00076 00077 #endif 00078 00079 /* 00080 * Change log : 00081 * 00082 * $Log: UDPEndpoint.h,v $ 00083 * Revision 1.2 2004/09/12 20:10:47 wachter 00084 * Documentation-fixes 00085 * 00086 * Revision 1.1.1.1 2004/05/22 17:23:41 cvsadm 00087 * created new repository GT2004_WM 00088 * 00089 * Revision 1.5 2004/01/26 13:44:07 wachter 00090 * shared-memory-buffers now have variable sizes 00091 * 00092 * Revision 1.4 2004/01/09 15:44:30 wachter 00093 * Worked on with the Dog-Discovery-Protocol 00094 * 00095 * Revision 1.3 2003/12/11 15:02:37 wachter 00096 * Low-level TCP and UDP functions for aperios now working. 00097 * 00098 * Revision 1.2 2003/12/10 09:56:42 dueffert 00099 * doxygen bugs fixed 00100 * 00101 * Revision 1.1 2003/12/03 14:21:52 wachter 00102 * Splitted IPEndpoint.* 00103 * 00104 * 00105 */