本文整理汇总了C++中Address::getSockAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::getSockAddr方法的具体用法?C++ Address::getSockAddr怎么用?C++ Address::getSockAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getSockAddr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: peekFrom
/** \brief peek the given number of bytes
*
* Read size bytes into the buffer. Wait until size Bytes are available
* On Dgram sockets data maight be lossed, if size is smaller then the
* incomming package. This situation will not be treated as an error.
* The read bytes will not be removed from the in buffer. A call to
* recv after peek will result in the same data.
*
* \param buf Pointer to the data buffer.
* \param size Maximum count of bytes to read.
* \param from Will be overwritten with the address of the sender
*
* \see recv Socket::recv
*/
int DgramSocket::peekFrom(void *buf,int size,Address &from)
{
int len;
SocketLenT addrLen=from.getSockAddrSize();
len=recvfrom(_sd,
(char*)buf,
size,
MSG_PEEK,
from.getSockAddr(),
&addrLen);
if(len==-1)
{
#if defined WIN32
if(getError()==WSAECONNRESET)
{
throw SocketConnReset("recvfrom");
}
if(getError()==WSAEMSGSIZE)
{
len=size;
}
else
#endif
throw SocketError("recvfrom()");
}
return len;
}
示例2: leave
/** \brief Leave a multicast group
*
* Don't receive messages from the given group.
*
* \param group Multicast group
* \param interf Which network interface to use. (Default AnyAddress)
*/
void DgramSocket::leave(const Address &group,const Address &interf)
{
struct ip_mreq joinAddr;
int rc;
// group to join
joinAddr.imr_multiaddr.s_addr
= ((sockaddr_in*)group.getSockAddr())->sin_addr.s_addr;
// interface that joins. (equal to bind address)
joinAddr.imr_interface
= ((sockaddr_in*)interf.getSockAddr())->sin_addr;
rc=setsockopt(_sd,
IPPROTO_IP,
IP_DROP_MEMBERSHIP,
(SocketOptT*)&joinAddr,
sizeof(joinAddr));
if(rc < 0)
{
throw SocketError("setsockopt(IPPROTO_IP,IP_DROP_MEMBERSHIP)");
}
}
示例3: sendTo
/** \brief Write the given number of bytes to the socket
*
* Write size bytes to the socket. This method maight block, if the
* output buffer is full.
*
* \param buf Pointer to the data buffer.
* \param size number of bytes to write
* \param to destination address
*
* \see recv Socket::send
*/
int DgramSocket::sendTo(const void *buf,int size,const Address &to)
{
int len;
// send Request
len=sendto(_sd,
(const char*)buf,size,
0,
to.getSockAddr(),
to.getSockAddrSize());
if(len == -1)
{
throw SocketError("sendto()");
}
return len;
}