Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 1824

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qnetworkdatagram.cpp -->
  <title>QNetworkDatagram Class | Qt Network 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtnetwork-index.html">Qt Network</a></td><td ><a href="qtnetwork-module.html">C++ Classes</a></td><td >QNetworkDatagram</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#feature-support">Feature support</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QNetworkDatagram Class</h1>
<!-- $$$QNetworkDatagram-brief -->
<p>The <a href="qnetworkdatagram.html">QNetworkDatagram</a> class provides the data and metadata of a UDP datagram. <a href="#details">More...</a></p>
<!-- @@@QNetworkDatagram -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QNetworkDatagram&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += network</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.8</td></tr></table></div><ul>
<li><a href="qnetworkdatagram-members.html">List of all members, including inherited members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#QNetworkDatagram-1">QNetworkDatagram</a></b>(const QByteArray &amp;<i>data</i>, const QHostAddress &amp;<i>destinationAddress</i> = QHostAddress(), quint16 <i>port</i> = 0)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#QNetworkDatagram-2">QNetworkDatagram</a></b>(const QNetworkDatagram &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#QNetworkDatagram-3">QNetworkDatagram</a></b>(QNetworkDatagram &amp;&amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#dtor.QNetworkDatagram">~QNetworkDatagram</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#clear">clear</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#data">data</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QHostAddress </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#destinationPort">destinationPort</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#hopLimit">hopLimit</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> uint </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#interfaceIndex">interfaceIndex</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#isNull">isNull</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#isValid">isValid</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QNetworkDatagram </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#makeReply">makeReply</a></b>(const QByteArray &amp;<i>data</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QHostAddress </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#senderAddress">senderAddress</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#senderPort">senderPort</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#setData">setData</a></b>(const QByteArray &amp;<i>data</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#setDestination">setDestination</a></b>(const QHostAddress &amp;<i>address</i>, quint16 <i>port</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#setHopLimit">setHopLimit</a></b>(int <i>count</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#setInterfaceIndex">setInterfaceIndex</a></b>(uint <i>index</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#setSender">setSender</a></b>(const QHostAddress &amp;<i>address</i>, quint16 <i>port</i> = 0)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#swap">swap</a></b>(QNetworkDatagram &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QNetworkDatagram &amp;</td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#operator-eq">operator=</a></b>(const QNetworkDatagram &amp;<i>other</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QNetworkDatagram &amp;</td><td class="memItemRight bottomAlign"><b><a href="qnetworkdatagram.html#operator-eq-1">operator=</a></b>(QNetworkDatagram &amp;&amp;<i>other</i>)</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QNetworkDatagram-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qnetworkdatagram.html">QNetworkDatagram</a> class provides the data and metadata of a UDP datagram.</p>
<p><a href="qnetworkdatagram.html">QNetworkDatagram</a> can be used with the <a href="qudpsocket.html">QUdpSocket</a> class to represent the full information contained in a UDP (User Datagram Protocol) datagram. <a href="qnetworkdatagram.html">QNetworkDatagram</a> encapsulates the following information of a datagram:</p>
<ul>
<li>the payload data;</li>
<li>the sender address and port number;</li>
<li>the destination address and port number;</li>
<li>the remaining hop count limit (on IPv4, this field is usually called &quot;time to live&quot; - TTL);</li>
<li>the network interface index the datagram was received on or to be sent on.</li>
</ul>
<p><a href="qudpsocket.html">QUdpSocket</a> will try to match a common behavior as much as possible on all operating systems, but not all of the metadata above can be obtained in some operating systems. Metadata that cannot be set on the datagram when sending with <a href="qudpsocket.html#writeDatagram">QUdpSocket::writeDatagram</a>() will be silently discarded.</p>
<p>Upon reception, the <a href="qnetworkdatagram.html#senderAddress">senderAddress</a>() and <a href="qnetworkdatagram.html#senderPort">senderPort</a>() properties contain the address and port of the peer that sent the datagram, while <a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>() and <a href="qnetworkdatagram.html#destinationPort">destinationPort</a>() contain the target that was contained in the datagram. That is usually an address local to the current machine, but it can also be an IPv4 broadcast address (such as &quot;255.255.255.255&quot;) or an IPv4 or IPv6 multicast address. Applications may find it useful to determine if the datagram was sent specifically to this machine via unicast addressing or whether it was sent to multiple destinations.</p>
<p>When sending, the <a href="qnetworkdatagram.html#senderAddress">senderAddress</a>() and <a href="qnetworkdatagram.html#senderPort">senderPort</a>() should contain the local address to be used when sending. The sender address must be an address that is assigned to this machine, which can be obtained using <a href="qnetworkinterface.html">QNetworkInterface</a>, and the port number must be the port number that the socket is bound to. Either field can be left unset and will be filled in by the operating system with default values. The <a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>() and <a href="qnetworkdatagram.html#destinationPort">destinationPort</a>() fields may be set to a target address different from the one the UDP socket is currently associated with.</p>
<p>Usually, when sending a datagram in reply to a datagram previously received, one will set the <a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>() to be the <a href="qnetworkdatagram.html#senderAddress">senderAddress</a>() of the incoming datagram and similarly for the port numbers. To facilitate this common process, <a href="qnetworkdatagram.html">QNetworkDatagram</a> provides the function <a href="qnetworkdatagram.html#makeReply">makeReply</a>().</p>
<p>The hopCount() function contains, for a received datagram, the remaining hop count limit for the packet. When sending, it contains the hop count limit to be set. Most protocols will leave this value set to the default and let the operating system decide on the best value to be used. Multicasting over IPv4 often uses this field to indicate the scope of the multicast group (link-local, local to an organization or global).</p>
<p>The <a href="qnetworkdatagram.html#interfaceIndex">interfaceIndex</a>() function contains the index of the operating system's interface that received the packet. This value is the same one that can be set on a <a href="qhostaddress.html#scopeId">QHostAddress::scopeId</a>() property and matches the <a href="qnetworkinterface.html#index">QNetworkInterface::index</a>() property. When sending packets to global addresses, it is not necessary to set the interface index as the operating system will choose the correct one using the system routing table. This property is important when sending datagrams to link-local destinations, whether unicast or multicast.</p>
<a name="feature-support"></a>
<h3 >Feature support</h3>
<p>Some features of <a href="qnetworkdatagram.html">QNetworkDatagram</a> are not supported in all operating systems. Only the address and ports of the remote host (sender in received packets and destination for outgoing packets) are supported in all systems. On most operating systems, the other features are supported only for IPv6. Software should check at runtime whether the rest could be determined for IPv4 addresses.</p>
<p>The current feature support is as follows:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Operating system</th><th >Local address</th><th >Hop count</th><th >Interface index</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="../qtcore/qtcore-attribution-freebsd.html#freebsd">FreeBSD</a></td><td >Supported</td><td >Supported</td><td >Only for IPv6</td></tr>
<tr valign="top" class="even"><td >Linux</td><td >Supported</td><td >Supported</td><td >Supported</td></tr>
<tr valign="top" class="odd"><td >OS X</td><td >Supported</td><td >Supported</td><td >Only for IPv6</td></tr>
<tr valign="top" class="even"><td >Other Unix supporting RFC 3542</td><td >Only for IPv6</td><td >Only for IPv6</td><td >Only for IPv6</td></tr>
<tr valign="top" class="odd"><td >Windows (desktop)</td><td >Supported</td><td >Supported</td><td >Supported</td></tr>
<tr valign="top" class="even"><td >Windows RT</td><td >Not supported</td><td >Not supported</td><td >Not supported</td></tr>
</table></div>
</div>
<p><b>See also </b><a href="qudpsocket.html">QUdpSocket</a> and <a href="qnetworkinterface.html">QNetworkInterface</a>.</p>
<!-- @@@QNetworkDatagram -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QNetworkDatagram[overload1]$$$QNetworkDatagram -->
<h3 class="fn" id="QNetworkDatagram"><a name="QNetworkDatagram"></a>QNetworkDatagram::<span class="name">QNetworkDatagram</span>()</h3>
<p>Creates a <a href="qnetworkdatagram.html">QNetworkDatagram</a> object with no payload data and undefined destination address.</p>
<p>The payload can be modified by using <a href="qnetworkdatagram.html#setData">setData</a>() and the destination address can be set with <a href="qnetworkdatagram.html#setDestination">setDestination</a>().</p>
<p>If the destination address is left undefined, <a href="qudpsocket.html#writeDatagram">QUdpSocket::writeDatagram</a>() will attempt to send the datagram to the address last associated with, by using <a href="qabstractsocket.html#connectToHost">QUdpSocket::connectToHost</a>().</p>
<!-- @@@QNetworkDatagram -->
<!-- $$$QNetworkDatagram$$$QNetworkDatagramconstQByteArray&constQHostAddress&quint16 -->
<h3 class="fn" id="QNetworkDatagram-1"><a name="QNetworkDatagram-1"></a>QNetworkDatagram::<span class="name">QNetworkDatagram</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>, const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp;<i>destinationAddress</i> = QHostAddress(), <span class="type"><a href="../qtcore/qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> = 0)</h3>
<p>Creates a <a href="qnetworkdatagram.html">QNetworkDatagram</a> object and sets <i>data</i> as the payload data, along with <i>destinationAddress</i> and <i>port</i> as the destination address of the datagram.</p>
<!-- @@@QNetworkDatagram -->
<!-- $$$QNetworkDatagram$$$QNetworkDatagramconstQNetworkDatagram& -->
<h3 class="fn" id="QNetworkDatagram-2"><a name="QNetworkDatagram-2"></a>QNetworkDatagram::<span class="name">QNetworkDatagram</span>(const <span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;<i>other</i>)</h3>
<p>Creates a copy of the <i>other</i> datagram, including the payload and metadata.</p>
<p>To create a datagram suitable for sending in a reply, use <a href="qnetworkdatagram.html#makeReply">QNetworkDatagram::makeReply</a>();</p>
<!-- @@@QNetworkDatagram -->
<!-- $$$QNetworkDatagram$$$QNetworkDatagramQNetworkDatagram&& -->
<h3 class="fn" id="QNetworkDatagram-3"><a name="QNetworkDatagram-3"></a>QNetworkDatagram::<span class="name">QNetworkDatagram</span>(<span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;&amp;<i>other</i>)</h3>
<p>Move-copy constructor.</p><!-- @@@QNetworkDatagram -->
<!-- $$$~QNetworkDatagram[overload1]$$$~QNetworkDatagram -->
<h3 class="fn" id="dtor.QNetworkDatagram"><a name="dtor.QNetworkDatagram"></a>QNetworkDatagram::<span class="name">~QNetworkDatagram</span>()</h3>
<p>Destroys the instance of QNetworkDatagram.</p><!-- @@@~QNetworkDatagram -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn" id="clear"><a name="clear"></a><span class="type">void</span> QNetworkDatagram::<span class="name">clear</span>()</h3>
<p>Clears the payload data and metadata in this <a href="qnetworkdatagram.html">QNetworkDatagram</a> object, resetting them to their default values.</p>
<!-- @@@clear -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn" id="data"><a name="data"></a><span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> QNetworkDatagram::<span class="name">data</span>() const</h3>
<p>Returns the data payload of this datagram. For a datagram received from the network, it contains the payload of the datagram. For an outgoing datagram, it is the datagram to be sent.</p>
<p>Note that datagrams can be transmitted with no data, so the returned <a href="../qtcore/qbytearray.html">QByteArray</a> may be empty.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#setData">setData</a>().</p>
<!-- @@@data -->
<!-- $$$destinationAddress[overload1]$$$destinationAddress -->
<h3 class="fn" id="destinationAddress"><a name="destinationAddress"></a><span class="type"><a href="qhostaddress.html">QHostAddress</a></span> QNetworkDatagram::<span class="name">destinationAddress</span>() const</h3>
<p>Returns the destination address associated with this datagram. For a datagram received from the network, it is the address the peer node sent the datagram to, which can either be a local address of this machine or a multicast or broadcast address. For an outgoing datagrams, it is the address the datagram should be sent to.</p>
<p>If no destination address was set on this datagram, the returned object will report true to <a href="qhostaddress.html#isNull">QHostAddress::isNull</a>().</p>
<p><b>See also </b><a href="qnetworkdatagram.html#senderAddress">senderAddress</a>(), <a href="qnetworkdatagram.html#destinationPort">destinationPort</a>(), and <a href="qnetworkdatagram.html#setDestination">setDestination</a>().</p>
<!-- @@@destinationAddress -->
<!-- $$$destinationPort[overload1]$$$destinationPort -->
<h3 class="fn" id="destinationPort"><a name="destinationPort"></a><span class="type">int</span> QNetworkDatagram::<span class="name">destinationPort</span>() const</h3>
<p>Returns the port number of the destination associated with this datagram. For a datagram received from the network, it is the local port number that the peer node sent the datagram to. For an outgoing datagram, it is the peer port the datagram should be sent to.</p>
<p>If no destination address was associated with this datagram, this function returns -1.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>(), <a href="qnetworkdatagram.html#senderPort">senderPort</a>(), and <a href="qnetworkdatagram.html#setDestination">setDestination</a>().</p>
<!-- @@@destinationPort -->
<!-- $$$hopLimit[overload1]$$$hopLimit -->
<h3 class="fn" id="hopLimit"><a name="hopLimit"></a><span class="type">int</span> QNetworkDatagram::<span class="name">hopLimit</span>() const</h3>
<p>Returns the hop count limit associated with this datagram. The hop count limit is the number of nodes that are allowed to forward the IP packet before it expires and an error is sent back to the sender of the datagram. In IPv4, this value is usually known as &quot;time to live&quot; (TTL).</p>
<p>If this datagram was received from the network, this is the remaining hop count of the datagram after reception and was decremented by 1 by each node that forwarded the packet. A value of -1 indicates that the hop limit count not be obtained.</p>
<p>If this is an outgoing datagram, this is the value to be set in the IP header upon sending. A value of -1 indicates the operating system should choose the value.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#setHopLimit">setHopLimit</a>().</p>
<!-- @@@hopLimit -->
<!-- $$$interfaceIndex[overload1]$$$interfaceIndex -->
<h3 class="fn" id="interfaceIndex"><a name="interfaceIndex"></a><span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> QNetworkDatagram::<span class="name">interfaceIndex</span>() const</h3>
<p>Returns the interface index this datagram is associated with. The interface index is a positive number that uniquely identifies the network interface in the operating system. This number matches the value returned by <a href="qnetworkinterface.html#index">QNetworkInterface::index</a>() for the interface.</p>
<p>If this datagram was received from the network, this is the index of the interface that the packet was received from. If this is an outgoing datagram, this is the index of the interface that the datagram should be sent on.</p>
<p>A value of 0 indicates that the interface index is unknown.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#setInterfaceIndex">setInterfaceIndex</a>().</p>
<!-- @@@interfaceIndex -->
<!-- $$$isNull[overload1]$$$isNull -->
<h3 class="fn" id="isNull"><a name="isNull"></a><span class="type">bool</span> QNetworkDatagram::<span class="name">isNull</span>() const</h3>
<p>Returns true if this <a href="qnetworkdatagram.html">QNetworkDatagram</a> object is null. This function is the opposite of <a href="qnetworkdatagram.html#isValid">isValid</a>().</p>
<!-- @@@isNull -->
<!-- $$$isValid[overload1]$$$isValid -->
<h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QNetworkDatagram::<span class="name">isValid</span>() const</h3>
<p>Returns true if this <a href="qnetworkdatagram.html">QNetworkDatagram</a> object is valid. A valid <a href="qnetworkdatagram.html">QNetworkDatagram</a> object contains at least one sender or receiver address. Valid datagrams can contain empty payloads.</p>
<!-- @@@isValid -->
<!-- $$$makeReply[overload1]$$$makeReplyconstQByteArray& -->
<h3 class="fn" id="makeReply"><a name="makeReply"></a><span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> QNetworkDatagram::<span class="name">makeReply</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>) const</h3>
<p>Creates a new <a href="qnetworkdatagram.html">QNetworkDatagram</a> representing a reply to this incoming datagram and sets the payload data to <i>data</i>. This function is a very convenient way of responding to a datagram back to the original sender.</p>
<p>Example:</p>
<pre class="cpp">

  <span class="type">void</span> Server<span class="operator">::</span>readPendingDatagrams()
  {
      <span class="keyword">while</span> (udpSocket<span class="operator">-</span><span class="operator">&gt;</span>hasPendingDatagrams()) {
          <span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> datagram <span class="operator">=</span> udpSocket<span class="operator">-</span><span class="operator">&gt;</span>receiveDatagram();
          <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> replyData <span class="operator">=</span> processThePayload(datagram<span class="operator">.</span>data());
          udpSocket<span class="operator">-</span><span class="operator">&gt;</span>writeDatagram(datagram<span class="operator">.</span>makeReply(replyData));
      }
  }

</pre>
<p>This function is especially convenient since it will automatically copy parameters from this datagram to the new datagram as appropriate:</p>
<ul>
<li>this datagram's sender address and port are copied to the new datagram's destination address and port;</li>
<li>this datagram's interface index, if any, is copied to the new datagram's interface index;</li>
<li>this datagram's destination address and port are copied to the new datagram's sender address and port only if the address is IPv6 global (non-multicast) address;</li>
<li>the hop count limit on the new datagram is reset to the default (-1);</li>
</ul>
<p>If <a href="qnetworkdatagram.html">QNetworkDatagram</a> is modified in a future version of Qt to carry further metadata, this function will copy that metadata as appropriate.</p>
<p>This datagram's destination address is not copied if it is an IPv4 address because it is not possible to tell an IPv4 broadcast address apart from a regular IPv4 address without an exhaustive search of all addresses assigned to this machine. Attempting to send a datagram with the sender address equal to the broadcast address is likely to fail. However, this should not affect the communication as network interfaces with multiple IPv4 addresses are uncommon, so the address the operating system will select will likely be one the peer will understand.</p>
<p><b>Note: </b>This function comes with both rvalue- and lvalue-reference qualifier overloads, so it is a good idea to make sure this object is rvalue, if possible, before calling makeReply, so as to make better use of move semantics. To achieve that, the example above would use:</p><pre class="cpp">

  udpSocket<span class="operator">-</span><span class="operator">&gt;</span>writeDatagram(std<span class="operator">::</span>move(datagram)<span class="operator">.</span>makeReply(replyData));

</pre>
<!-- @@@makeReply -->
<!-- $$$senderAddress[overload1]$$$senderAddress -->
<h3 class="fn" id="senderAddress"><a name="senderAddress"></a><span class="type"><a href="qhostaddress.html">QHostAddress</a></span> QNetworkDatagram::<span class="name">senderAddress</span>() const</h3>
<p>Returns the sender address associated with this datagram. For a datagram received from the network, it is the address of the peer node that sent the datagram. For an outgoing datagrams, it is the local address to be used when sending.</p>
<p>If no sender address was set on this datagram, the returned object will report true to <a href="qhostaddress.html#isNull">QHostAddress::isNull</a>().</p>
<p><b>See also </b><a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>(), <a href="qnetworkdatagram.html#senderPort">senderPort</a>(), and <a href="qnetworkdatagram.html#setSender">setSender</a>().</p>
<!-- @@@senderAddress -->
<!-- $$$senderPort[overload1]$$$senderPort -->
<h3 class="fn" id="senderPort"><a name="senderPort"></a><span class="type">int</span> QNetworkDatagram::<span class="name">senderPort</span>() const</h3>
<p>Returns the port number of the sender associated with this datagram. For a datagram received from the network, it is the port number that the peer node sent the datagram from. For an outgoing datagram, it is the local port the datagram should be sent from.</p>
<p>If no sender address was associated with this datagram, this function returns -1.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#senderAddress">senderAddress</a>(), <a href="qnetworkdatagram.html#destinationPort">destinationPort</a>(), and <a href="qnetworkdatagram.html#setSender">setSender</a>().</p>
<!-- @@@senderPort -->
<!-- $$$setData[overload1]$$$setDataconstQByteArray& -->
<h3 class="fn" id="setData"><a name="setData"></a><span class="type">void</span> QNetworkDatagram::<span class="name">setData</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>data</i>)</h3>
<p>Sets the data payload of this datagram to <i>data</i>. It is usually not necessary to call this function on received datagrams. For outgoing datagrams, this function sets the data to be sent on the network.</p>
<p>Since datagrams can empty, an empty <a href="../qtcore/qbytearray.html">QByteArray</a> is a valid value for <i>data</i>.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#data">data</a>().</p>
<!-- @@@setData -->
<!-- $$$setDestination[overload1]$$$setDestinationconstQHostAddress&quint16 -->
<h3 class="fn" id="setDestination"><a name="setDestination"></a><span class="type">void</span> QNetworkDatagram::<span class="name">setDestination</span>(const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp;<i>address</i>, <span class="type"><a href="../qtcore/qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i>)</h3>
<p>Sets the destination address associated with this datagram to be the address <i>address</i> and port number <i>port</i>. The destination address and port numbers are usually set by <a href="qudpsocket.html">QUdpSocket</a> upon reception, so there's no need to call this function on a received datagram.</p>
<p>For outgoing datagrams, this function can be used to set the address the datagram should be sent to. It can be the unicast address used to communicate with the peer or a broadcast or multicast address to send to a group of devices.</p>
<p><b>See also </b><a href="qudpsocket.html#writeDatagram">QUdpSocket::writeDatagram</a>(), <a href="qnetworkdatagram.html#destinationAddress">destinationAddress</a>(), <a href="qnetworkdatagram.html#destinationPort">destinationPort</a>(), and <a href="qnetworkdatagram.html#setSender">setSender</a>().</p>
<!-- @@@setDestination -->
<!-- $$$setHopLimit[overload1]$$$setHopLimitint -->
<h3 class="fn" id="setHopLimit"><a name="setHopLimit"></a><span class="type">void</span> QNetworkDatagram::<span class="name">setHopLimit</span>(<span class="type">int</span> <i>count</i>)</h3>
<p>Sets the hop count limit associated with this datagram to <i>count</i>. The hop count limit is the number of nodes that are allowed to forward the IP packet before it expires and an error is sent back to the sender of the datagram. In IPv4, this value is usually known as &quot;time to live&quot; (TTL).</p>
<p>It is usually not necessary to call this function on datagrams received from the network.</p>
<p>If this is an outgoing packet, this is the value to be set in the IP header upon sending. The valid range for the value is 1 to 255. This function also accepts a value of -1 to indicate that the operating system should choose the value.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#hopLimit">hopLimit</a>().</p>
<!-- @@@setHopLimit -->
<!-- $$$setInterfaceIndex[overload1]$$$setInterfaceIndexuint -->
<h3 class="fn" id="setInterfaceIndex"><a name="setInterfaceIndex"></a><span class="type">void</span> QNetworkDatagram::<span class="name">setInterfaceIndex</span>(<span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> <i>index</i>)</h3>
<p>Sets the interface index this datagram is associated with to <i>index</i>. The interface index is a positive number that uniquely identifies the network interface in the operating system. This number matches the value returned by <a href="qnetworkinterface.html#index">QNetworkInterface::index</a>() for the interface.</p>
<p>It is usually not necessary to call this function on datagrams received from the network.</p>
<p>If this is an outgoing packet, this is the index of the interface the datagram should be sent on. A value of 0 indicates that the operating system should choose the interface based on other factors.</p>
<p>Note that the interface index can also be set with <a href="qhostaddress.html#setScopeId">QHostAddress::setScopeId</a>() for IPv6 destination addresses and then with <a href="qnetworkdatagram.html#setDestination">setDestination</a>(). If the scope ID set in the destination address and <i>index</i> are different and neither is zero, it is undefined which interface the operating system will send the datagram on.</p>
<p><b>See also </b><a href="qnetworkdatagram.html#interfaceIndex">interfaceIndex</a>() and setInterfaceIndex().</p>
<!-- @@@setInterfaceIndex -->
<!-- $$$setSender[overload1]$$$setSenderconstQHostAddress&quint16 -->
<h3 class="fn" id="setSender"><a name="setSender"></a><span class="type">void</span> QNetworkDatagram::<span class="name">setSender</span>(const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp;<i>address</i>, <span class="type"><a href="../qtcore/qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> = 0)</h3>
<p>Sets the sender address associated with this datagram to be the address <i>address</i> and port number <i>port</i>. The sender address and port numbers are usually set by <a href="qudpsocket.html">QUdpSocket</a> upon reception, so there's no need to call this function on a received datagram.</p>
<p>For outgoing datagrams, this function can be used to set the address the datagram should carry. The address <i>address</i> must usually be one of the local addresses assigned to this machine, which can be obtained using <a href="qnetworkinterface.html">QNetworkInterface</a>. If left unset, the operating system will choose the most appropriate address to use given the destination in question.</p>
<p>The port number <i>port</i> must be the port number associated with the socket, if there is one. The value of 0 can be used to indicate that the operating system should choose the port number.</p>
<p><b>See also </b><a href="qudpsocket.html#writeDatagram">QUdpSocket::writeDatagram</a>(), <a href="qnetworkdatagram.html#senderAddress">senderAddress</a>(), <a href="qnetworkdatagram.html#senderPort">senderPort</a>(), and <a href="qnetworkdatagram.html#setDestination">setDestination</a>().</p>
<!-- @@@setSender -->
<!-- $$$swap[overload1]$$$swapQNetworkDatagram& -->
<h3 class="fn" id="swap"><a name="swap"></a><span class="type">void</span> QNetworkDatagram::<span class="name">swap</span>(<span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;<i>other</i>)</h3>
<!-- @@@swap -->
<!-- $$$operator=[overload1]$$$operator=constQNetworkDatagram& -->
<h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;QNetworkDatagram::<span class="name">operator=</span>(const <span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;<i>other</i>)</h3>
<p>Copies the <i>other</i> datagram, including the payload and metadata.</p>
<p>To create a datagram suitable for sending in a reply, use <a href="qnetworkdatagram.html#makeReply">QNetworkDatagram::makeReply</a>();</p>
<!-- @@@operator= -->
<!-- $$$operator=$$$operator=QNetworkDatagram&& -->
<h3 class="fn" id="operator-eq-1"><a name="operator-eq-1"></a><span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;QNetworkDatagram::<span class="name">operator=</span>(<span class="type"><a href="qnetworkdatagram.html#QNetworkDatagram">QNetworkDatagram</a></span> &amp;&amp;<i>other</i>)</h3>
<p>Move-assignment operator.</p><!-- @@@operator= -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>