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 #include "stdafx.h"
00037 #include "UDPSocket.h"
00038
00039 #include "ErrorHandlerMacros.h"
00040 #include "Array_ptr.h"
00041
00042 #include <memory>
00043
00044 #ifdef _MEMORY_DEBUG
00045 #define new DEBUG_NEW
00046 #define malloc DEBUG_MALLOC
00047 static char THIS_FILE[] = __FILE__;
00048 #endif
00049
00050 KOMODIA_NAMESPACE_START
00051
00052 #define CUDPSocket_Class "CUDPSocket"
00053
00054 CUDPSocket::CUDPSocket(BOOL bRawSocket) : CSocket(bRawSocket)
00055 {
00056 try
00057 {
00058
00059 SetName(CUDPSocket_Class);
00060 }
00061 ERROR_HANDLER("CUDPSocket")
00062 }
00063
00064 CUDPSocket::~CUDPSocket()
00065 {
00066 }
00067
00068 BOOL CUDPSocket::Create()
00069 {
00070 try
00071 {
00072
00073 SetProtocol(IPPROTO_UDP);
00074
00075
00076 return CSocket::Create(IPPROTO_UDP);
00077 }
00078 ERROR_HANDLER_RETURN("Create",FALSE)
00079 }
00080
00081 BOOL CUDPSocket::Send(IP aDestinationAddress,
00082 unsigned short usDestinationPort,
00083 const char* pBuffer,
00084 unsigned short usBufferLength)
00085 {
00086 try
00087 {
00088
00089 return CSocket::Send(aDestinationAddress,
00090 pBuffer,
00091 usBufferLength,
00092 usDestinationPort);
00093 }
00094 ERROR_HANDLER_RETURN("Send",FALSE)
00095 }
00096
00097 BOOL CUDPSocket::Send(const std::string& rDestinationAddress,
00098 unsigned short usDestinationPort,
00099 const char* pBuffer,
00100 unsigned short usBufferLength)
00101 {
00102 try
00103 {
00104
00105 return Send(rDestinationAddress,
00106 usDestinationPort,
00107 pBuffer,
00108 usBufferLength);
00109 }
00110 ERROR_HANDLER_RETURN("Send",FALSE)
00111 }
00112
00113 int CUDPSocket::Receive(char* pBuffer,
00114 unsigned long ulBufferLength)
00115 {
00116 try
00117 {
00118
00119 return CSocket::Receive(pBuffer,
00120 ulBufferLength);
00121 }
00122 ERROR_HANDLER_RETURN("Receive",GetErrorCode())
00123 }
00124
00125 int CUDPSocket::Receive(char* pBuffer,
00126 unsigned long ulBufferLength,
00127 IP& rIP,
00128 unsigned short& rSourcePort)
00129 {
00130 try
00131 {
00132
00133 return ReceiveFrom(pBuffer,
00134 ulBufferLength,
00135 rIP,
00136 rSourcePort);
00137 }
00138 ERROR_HANDLER_RETURN("Receive",GetErrorCode())
00139 }
00140
00141 KOMODIA_NAMESPACE_END