Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __CXUTILS_SOCKET_UDP_CLIENT_H
00041 #define __CXUTILS_SOCKET_UDP_CLIENT_H
00042
00043 #include "cxutils/cxbase.h"
00044 #include "cxutils/networking/socket.h"
00045 #include "cxutils/mutex.h"
00046
00047 namespace CxUtils
00048 {
00059 class CX_UTILS_DLL UdpClient : public Socket
00060 {
00061 friend class UdpServer;
00062 public:
00063 UdpClient();
00064 virtual ~UdpClient();
00065 int InitializeSocket(const IP4Address& ipAddress,
00066 const unsigned short destinationPort,
00067 const unsigned short sourcePort = 0);
00068 int InitializeMulticastSocket(const IP4Address& multicastGroup,
00069 const unsigned short destinationPort,
00070 const unsigned char ttl = 16,
00071 const bool broadcastFlag = false,
00072 const unsigned short sourcePort = 0,
00073 const bool allowReuse = true);
00074 virtual void Shutdown();
00075 inline IP4Address GetConnectionAddress() const { return mConnectionID; }
00076 inline unsigned short GetDestinationPort() const { return mDestinationPort; }
00077 inline unsigned short GetSourcePort() const { return mSourcePort; }
00078 UdpClient* CreateNewDestination(const IP4Address& ipAddress,
00079 const unsigned short destinationPort = 0) const;
00080 private:
00081 virtual int SendFromBuffer(const char* buffer,
00082 const unsigned int length) const;
00083 virtual int RecvToBuffer(char* buffer,
00084 const unsigned int length,
00085 const long int timeOutMilliseconds = 0,
00086 IPAddress* ipAddress = NULL,
00087 unsigned short* port = NULL) const;
00088 int mDestinationPort;
00089 int mSourcePort;
00090 long mComputer;
00091 struct hostent* mHP;
00092 struct sockaddr_in mSendAddr;
00093 struct sockaddr_in mRecvAddr;
00094 IP4Address mConnectionID;
00095 bool mDuplicateSocket;
00096 };
00097 typedef UdpClient UdpSender;
00098 }
00099
00100 #endif
00101