00001 /* 00002 * udpsocket.h 00003 * 00004 * Created on: 02.03.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef UDPSOCKET_H_ 00009 #define UDPSOCKET_H_ 00010 00011 #include "ibrcommon/net/vinterface.h" 00012 #include "ibrcommon/net/vsocket.h" 00013 #include "ibrcommon/Exceptions.h" 00014 #include <list> 00015 #include <netinet/in.h> 00016 #include <arpa/inet.h> 00017 #include <sys/socket.h> 00018 #include <sys/types.h> 00019 00020 namespace ibrcommon 00021 { 00022 class udpsocket 00023 { 00024 public: 00025 class SocketException : public ibrcommon::Exception 00026 { 00027 public: 00028 SocketException(string error) : ibrcommon::Exception(error) 00029 {}; 00030 }; 00031 00032 virtual ~udpsocket(); 00033 00034 virtual void shutdown(); 00035 00036 int receive(char* data, size_t maxbuffer); 00037 int receive(char* data, size_t maxbuffer, std::string &address, unsigned int &port); 00038 00039 int send(const ibrcommon::vaddress &address, const unsigned int port, const char *data, const size_t length); 00040 00041 protected: 00042 udpsocket() throw (SocketException); 00043 vsocket _socket; 00044 struct sockaddr_in _sockaddr; 00045 }; 00046 } 00047 00048 #endif /* UDPSOCKET_H_ */