<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>UDPSocket class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.5 on Thu Oct 4 15:33:02 2001 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center> <hr><h1>UDPSocket Class Reference</h1>UDP sockets implement the TCP SOCK_DGRAM UDP protocol. Unreliable Datagram Protocol sockets. <a href="#_details">More...</a> <p> <code>#include <<a class="el" href="socket_h-source.html">socket.h</a>></code> <p> <p>Inheritance diagram for UDPSocket: <p><center><img src="class_udpsocket.gif" usemap="#UDPSocket_map" border="0"></center> <map name="UDPSocket_map"> <area href="class_socket.html" alt="Socket" shape="rect" coords="104,0,198,24"> <area href="class_udpbroadcast.html" alt="UDPBroadcast" shape="rect" coords="0,112,94,136"> <area href="class_udpreceive.html" alt="UDPReceive" shape="rect" coords="104,112,198,136"> <area href="class_udptransmit.html" alt="UDPTransmit" shape="rect" coords="208,112,302,136"> <area href="class_udpduplex.html" alt="UDPDuplex" shape="rect" coords="104,168,198,192"> <area href="class_udpduplex.html" alt="UDPDuplex" shape="rect" coords="208,168,302,192"> </map> <a href="class_udpsocket-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0> <tr><td colspan=2><br><h2>Public Methods</h2></td></tr> <tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="class_udpsocket.html#a0">UDPSocket</a> (void)</td></tr> <tr><td> </td><td><font size=-1><em>Create an unbound UDP socket, mostly for internal use.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="class_udpsocket.html#a1">UDPSocket</a> (const <a class="el" href="class_inetaddress.html">InetAddress</a> &bind, <a class="el" href="socket_h.html#a2">tpport_t</a> port)</td></tr> <tr><td> </td><td><font size=-1><em>Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it.</em> <a href="#a1">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top> </td><td valign=bottom><a class="el" href="class_udpsocket.html#a2">~UDPSocket</a> ()</td></tr> <tr><td> </td><td><font size=-1><em>Destroy a UDP socket as a socket.</em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="class_udpsocket.html#a3">setPeer</a> (const <a class="el" href="class_inethostaddress.html">InetHostAddress</a> &host, <a class="el" href="socket_h.html#a2">tpport_t</a> port)</td></tr> <tr><td> </td><td><font size=-1><em>set the peer address to send message packets to.</em> <a href="#a3">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="class_udpsocket.html#a4">Send</a> (void *buf, size_t len)</td></tr> <tr><td> </td><td><font size=-1><em>Send a message packet to a peer host.</em> <a href="#a4">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="class_udpsocket.html#a5">Recv</a> (void *buf, size_t len)</td></tr> <tr><td> </td><td><font size=-1><em>Receive a message from any host.</em> <a href="#a5">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top><a class="el" href="class_inethostaddress.html">InetHostAddress</a> </td><td valign=bottom><a class="el" href="class_udpsocket.html#a6">getPeer</a> (<a class="el" href="socket_h.html#a2">tpport_t</a> *port=NULL) const</td></tr> <tr><td> </td><td><font size=-1><em>Examine address of sender of next waiting packet.</em> <a href="#a6">More...</a><em></em></font><br><br></td></tr> <tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="class_udpsocket.html#a7">Peek</a> (void *buf, size_t len)</td></tr> <tr><td> </td><td><font size=-1><em>Examine contents of next waiting packet.</em> <a href="#a7">More...</a><em></em></font><br><br></td></tr> <tr><td colspan=2><br><h2>Protected Attributes</h2></td></tr> <tr><td nowrap align=right valign=top>struct sockaddr_in </td><td valign=bottom><a class="el" href="class_udpsocket.html#n0">peer</a></td></tr> </table> <hr><a name="_details"></a><h2>Detailed Description</h2> UDP sockets implement the TCP SOCK_DGRAM UDP protocol. Unreliable Datagram Protocol sockets. <p> They can be used to pass unverified messages between hosts, or to broadcast a specific message to an entire subnet. Please note that Streaming of realtime data commonly use <a class="el" href="class_udpduplex.html">UDPDuplex</a> related classes rather than UDPSocket. <p> In addition to connected TCP sessions, Common C++ supports UDP sockets and these also cover a range of functionality. Like a <a class="el" href="class_tcpsocket.html">TCPSocket</a>, A UDPSocket can be created bound to a specific network interface and/or port address, though this is not required. UDP sockets also are usually either connected or otherwise "associated" with a specific "peer" UDP socket. Since UDP sockets operate through discreet packets, there are no streaming operators used with UDP sockets. <p> In addition to the UDP "socket" class, there is a "<a class="el" href="class_udpbroadcast.html">UDPBroadcast</a>" class. The <a class="el" href="class_udpbroadcast.html">UDPBroadcast</a> is a socket that is set to send messages to a subnet as a whole rather than to an individual peer socket that it may be associated with. <p> UDP sockets are often used for building "realtime" media streaming protocols and full duplex messaging services. When used in this manner, typically a pair of UDP sockets are used together; one socket is used to send and the other to receive data with an associated pair of UDP sockets on a "peer" host. This concept is represented through the Common C++ <a class="el" href="class_udpduplex.html">UDPDuplex</a> object, which is a pair of sockets that communicate with another <a class="el" href="class_udpduplex.html">UDPDuplex</a> pair. <p> <dl compact><dt> <b>Author(s): </b><dd> David Sugar <<a href="mailto:dyfet@ostel.com">dyfet@ostel.com</a>> </dl> <p> <hr><h2>Constructor & Destructor Documentation</h2> <a name="a0" doxytag="UDPSocket::UDPSocket"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> UDPSocket::UDPSocket ( </b></td> <td valign="bottom"><b> void ) </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Create an unbound UDP socket, mostly for internal use. <p> </td> </tr> </table> <a name="a1" doxytag="UDPSocket::UDPSocket"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> UDPSocket::UDPSocket ( </b></td> <td valign="bottom"><b> const <a class="el" href="class_inetaddress.html">InetAddress</a> & <em>bind</em>, </b></td> </tr> <tr> <td></td> <td><b> <a class="el" href="socket_h.html#a2">tpport_t</a> <em>port</em> ) </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it. <p> On failure to bind, an exception is thrown.<dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>bind</em> </td><td> address to bind this socket to. </td></tr> <tr><td valign=top><em>port</em> </td><td> number to bind this socket to. </td></tr> </table> </dl> </td> </tr> </table> <a name="a2" doxytag="UDPSocket::~UDPSocket"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> UDPSocket::~UDPSocket ( </b></td> <td valign="bottom"><b> )<code> [inline]</code> </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Destroy a UDP socket as a socket. <p> </td> </tr> </table> <hr><h2>Member Function Documentation</h2> <a name="a7" doxytag="UDPSocket::Peek"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> int UDPSocket::Peek ( </b></td> <td valign="bottom"><b> void * <em>buf</em>, </b></td> </tr> <tr> <td></td> <td><b> size_t <em>len</em> )<code> [inline]</code> </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Examine contents of next waiting packet. <p> <dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>pointer</em> </td><td> to packet buffer for contents. </td></tr> <tr><td valign=top><em>len</em> </td><td> of packet buffer. </td></tr> </table> </dl><dl compact><dt> <b>Returns: </b><dd> number of bytes examined. </dl> </td> </tr> </table> <a name="a5" doxytag="UDPSocket::Recv"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> int UDPSocket::Recv ( </b></td> <td valign="bottom"><b> void * <em>buf</em>, </b></td> </tr> <tr> <td></td> <td><b> size_t <em>len</em> )<code> [inline]</code> </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Receive a message from any host. <p> <dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>pointer</em> </td><td> to packet buffer to receive. </td></tr> <tr><td valign=top><em>len</em> </td><td> of packet buffer to receive. </td></tr> </table> </dl><dl compact><dt> <b>Returns: </b><dd> number of bytes received. </dl> </td> </tr> </table> <a name="a4" doxytag="UDPSocket::Send"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> int UDPSocket::Send ( </b></td> <td valign="bottom"><b> void * <em>buf</em>, </b></td> </tr> <tr> <td></td> <td><b> size_t <em>len</em> )<code> [inline]</code> </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Send a message packet to a peer host. <p> <dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>pointer</em> </td><td> to packet buffer to send. </td></tr> <tr><td valign=top><em>len</em> </td><td> of packet buffer to send. </td></tr> </table> </dl><dl compact><dt> <b>Returns: </b><dd> number of bytes sent. </dl> </td> </tr> </table> <a name="a6" doxytag="UDPSocket::getPeer"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> <a class="el" href="class_inethostaddress.html">InetHostAddress</a> UDPSocket::getPeer ( </b></td> <td valign="bottom"><b> <a class="el" href="socket_h.html#a2">tpport_t</a> * <em>port</em> = NULL ) const </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> Examine address of sender of next waiting packet. <p> This also sets "peer" address to the sender so that the next "send" message acts as a "reply". This additional behavior overides the standard socket getSender behavior.<dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>pointer</em> </td><td> to hold port number. </td></tr> </table> </dl> <p> Reimplemented from <a class="el" href="class_socket.html#a3">Socket</a>. </td> </tr> </table> <a name="a3" doxytag="UDPSocket::setPeer"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> void UDPSocket::setPeer ( </b></td> <td valign="bottom"><b> const <a class="el" href="class_inethostaddress.html">InetHostAddress</a> & <em>ia</em>, </b></td> </tr> <tr> <td></td> <td><b> <a class="el" href="socket_h.html#a2">tpport_t</a> <em>port</em> ) </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> set the peer address to send message packets to. <p> This can be set before every <a class="el" href="class_udpsocket.html#a4">Send</a>() call if nessisary.<dl compact><dt> <b>Parameters: </b><dd> <table border=0 cellspacing=2 cellpadding=0> <tr><td valign=top><em>host</em> </td><td> address to send packets to. </td></tr> <tr><td valign=top><em>port</em> </td><td> number to deliver packets to. </td></tr> </table> </dl> </td> </tr> </table> <hr><h2>Member Data Documentation</h2> <a name="n0" doxytag="UDPSocket::peer"></a><p> <table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap valign="top"><b> struct sockaddr_in UDPSocket::peer<code> [protected]</code> </b></td> </tr> </table> </td> </tr> </table> <table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td> <p> </td> </tr> </table> <hr>The documentation for this class was generated from the following file:<ul> <li><a class="el" href="socket_h-source.html">socket.h</a></ul> <hr><address><small>Generated at Thu Oct 4 15:33:02 2001 for CommonC++ by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.5 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2001</small></address> </body> </html>