Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 6944

qt-doc-4.8.5-10.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qudpsocket.cpp -->
  <title>Qt 4.8: QUdpSocket Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtnetwork.html">QtNetwork</a></li>
<li>QUdpSocket</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<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="#symbian-platform-security-requirements">Symbian Platform Security Requirements</a></li>
</ul>
</div>
<h1 class="title">QUdpSocket Class Reference</h1>
<!-- $$$QUdpSocket-brief -->
<p>The QUdpSocket class provides a UDP socket. <a href="#details">More...</a></p>
<!-- @@@QUdpSocket -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QUdpSocket&gt;</span></pre><p><b>Inherits: </b><a href="qabstractsocket.html">QAbstractSocket</a>.</p>
<p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qudpsocket-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#BindFlag-enum">BindFlag</a></b> { ShareAddress, DontShareAddress, ReuseAddressHint, DefaultForPlatform }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#BindFlag-enum">BindMode</a></b></td></tr>
</table>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#QUdpSocket">QUdpSocket</a></b> ( QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#dtor.QUdpSocket">~QUdpSocket</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#bind">bind</a></b> ( const QHostAddress &amp; <i>address</i>, quint16 <i>port</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#bind-2">bind</a></b> ( const QHostAddress &amp; <i>address</i>, quint16 <i>port</i>, BindMode <i>mode</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#bind-3">bind</a></b> ( quint16 <i>port</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#bind-4">bind</a></b> ( quint16 <i>port</i>, BindMode <i>mode</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#hasPendingDatagrams">hasPendingDatagrams</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#joinMulticastGroup">joinMulticastGroup</a></b> ( const QHostAddress &amp; <i>groupAddress</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#joinMulticastGroup-2">joinMulticastGroup</a></b> ( const QHostAddress &amp; <i>groupAddress</i>, const QNetworkInterface &amp; <i>iface</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#leaveMulticastGroup">leaveMulticastGroup</a></b> ( const QHostAddress &amp; <i>groupAddress</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#leaveMulticastGroup-2">leaveMulticastGroup</a></b> ( const QHostAddress &amp; <i>groupAddress</i>, const QNetworkInterface &amp; <i>iface</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QNetworkInterface </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#multicastInterface">multicastInterface</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#pendingDatagramSize">pendingDatagramSize</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#readDatagram">readDatagram</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i>, QHostAddress * <i>address</i> = 0, quint16 * <i>port</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#setMulticastInterface">setMulticastInterface</a></b> ( const QNetworkInterface &amp; <i>iface</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#writeDatagram">writeDatagram</a></b> ( const char * <i>data</i>, qint64 <i>size</i>, const QHostAddress &amp; <i>address</i>, quint16 <i>port</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> qint64 </td><td class="memItemRight bottomAlign"><b><a href="qudpsocket.html#writeDatagram-2">writeDatagram</a></b> ( const QByteArray &amp; <i>datagram</i>, const QHostAddress &amp; <i>host</i>, quint16 <i>port</i> )</td></tr>
</table>
<ul>
<li class="fn">32 public functions inherited from <a href="qabstractsocket.html#public-functions">QAbstractSocket</a></li>
<li class="fn">33 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">6 signals inherited from <a href="qabstractsocket.html#signals">QAbstractSocket</a></li>
<li class="fn">4 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li class="fn">10 protected functions inherited from <a href="qabstractsocket.html#protected-functions">QAbstractSocket</a></li>
<li class="fn">5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
<li class="fn">2 protected slots inherited from <a href="qabstractsocket.html#protected-slots">QAbstractSocket</a></li>
</ul>
<a name="details"></a>
<!-- $$$QUdpSocket-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QUdpSocket class provides a UDP socket.</p>
<p>UDP (User Datagram Protocol) is a lightweight, unreliable, datagram-oriented, connectionless protocol. It can be used when reliability isn't important. QUdpSocket is a subclass of <a href="qabstractsocket.html">QAbstractSocket</a> that allows you to send and receive UDP datagrams.</p>
<p>The most common way to use this class is to bind to an address and port using <a href="qudpsocket.html#bind">bind</a>(), then call <a href="qudpsocket.html#writeDatagram">writeDatagram</a>() and <a href="qudpsocket.html#readDatagram">readDatagram</a>() to transfer data. If you want to use the standard <a href="qiodevice.html">QIODevice</a> functions <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), <a href="qiodevice.html#write">write</a>(), etc., you must first connect the socket directly to a peer by calling <a href="qabstractsocket.html#connectToHost">connectToHost</a>().</p>
<p>The socket emits the <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal every time a datagram is written to the network. If you just want to send datagrams, you don't need to call <a href="qudpsocket.html#bind">bind</a>().</p>
<p>The <a href="qiodevice.html#readyRead">readyRead</a>() signal is emitted whenever datagrams arrive. In that case, <a href="qudpsocket.html#hasPendingDatagrams">hasPendingDatagrams</a>() returns true. Call <a href="qudpsocket.html#pendingDatagramSize">pendingDatagramSize</a>() to obtain the size of the first pending datagram, and <a href="qudpsocket.html#readDatagram">readDatagram</a>() to read it.</p>
<p><b>Note:</b> An incoming datagram should be read when you receive the <a href="qiodevice.html#readyRead">readyRead</a>() signal, otherwise this signal will not be emitted for the next datagram.</p>
<p>Example:</p>
<pre class="cpp"> <span class="type">void</span> Server<span class="operator">::</span>initSocket()
 {
     udpSocket <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QUdpSocket</span>(<span class="keyword">this</span>);
     udpSocket<span class="operator">-</span><span class="operator">&gt;</span>bind(<span class="type"><a href="qhostaddress.html">QHostAddress</a></span><span class="operator">::</span>LocalHost<span class="operator">,</span> <span class="number">7755</span>);

     connect(udpSocket<span class="operator">,</span> SIGNAL(readyRead())<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(readPendingDatagrams()));
 }

 <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="qbytearray.html">QByteArray</a></span> datagram;
         datagram<span class="operator">.</span>resize(udpSocket<span class="operator">-</span><span class="operator">&gt;</span>pendingDatagramSize());
         <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> sender;
         <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> senderPort;

         udpSocket<span class="operator">-</span><span class="operator">&gt;</span>readDatagram(datagram<span class="operator">.</span>data()<span class="operator">,</span> datagram<span class="operator">.</span>size()<span class="operator">,</span>
                                 <span class="operator">&amp;</span>sender<span class="operator">,</span> <span class="operator">&amp;</span>senderPort);

         processTheDatagram(datagram);
     }
 }</pre>
<p>QUdpSocket also supports UDP multicast. Use <a href="qudpsocket.html#joinMulticastGroup">joinMulticastGroup</a>() and <a href="qudpsocket.html#leaveMulticastGroup">leaveMulticastGroup</a>() to control group membership, and <a href="qabstractsocket.html#SocketOption-enum">QAbstractSocket::MulticastTtlOption</a> and <a href="qabstractsocket.html#SocketOption-enum">QAbstractSocket::MulticastLoopbackOption</a> to set the TTL and loopback socket options. Use <a href="qudpsocket.html#setMulticastInterface">setMulticastInterface</a>() to control the outgoing interface for multicast datagrams, and <a href="qudpsocket.html#multicastInterface">multicastInterface</a>() to query it.</p>
<p>With QUdpSocket, you can also establish a virtual connection to a UDP server using <a href="qabstractsocket.html#connectToHost">connectToHost</a>() and then use <a href="qiodevice.html#read">read</a>() and <a href="qiodevice.html#write">write</a>() to exchange datagrams without specifying the receiver for each datagram.</p>
<p>The <a href="network-broadcastsender.html">Broadcast Sender</a>, <a href="network-broadcastreceiver.html">Broadcast Receiver</a>, <a href="network-multicastsender.html">Multicast Sender</a>, and <a href="network-multicastreceiver.html">Multicast Receiver</a> examples illustrate how to use QUdpSocket in applications.</p>
<a name="symbian-platform-security-requirements"></a>
<h3>Symbian Platform Security Requirements</h3>
<p>On Symbian, processes which use this class must have the <tt>NetworkServices</tt> platform security capability. If the client process lacks this capability, operations will result in a panic.</p>
<p>Platform security capabilities are added via the <a href="qmake-variable-reference.html#target-capability">TARGET.CAPABILITY</a> qmake variable.</p>
</div>
<p><b>See also </b><a href="qtcpsocket.html">QTcpSocket</a>.</p>
<!-- @@@QUdpSocket -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$BindFlag$$$DefaultForPlatform$$$ShareAddress$$$DontShareAddress$$$ReuseAddressHint -->
<h3 class="flags"><a name="BindFlag-enum"></a>enum QUdpSocket::<span class="name">BindFlag</span><br/>flags QUdpSocket::<span class="name">BindMode</span></h3>
<p>This enum describes the different flags you can pass to modify the behavior of <a href="qudpsocket.html#bind">QUdpSocket::bind</a>().</p>
<p><b>Note:</b> On Symbian OS bind flags behaviour depends on process capabilties. If process has NetworkControl capability, the bind attempt with ReuseAddressHint will always succeed even if the address and port is already bound by another socket with any flags. If process does not have NetworkControl capability, the bind attempt to address and port already bound by another socket will always fail.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QUdpSocket::ShareAddress</tt></td><td class="topAlign"><tt>0x1</tt></td><td class="topAlign">Allow other services to bind to the same address and port. This is useful when multiple processes share the load of a single service by listening to the same address and port (e.g&#x2e;, a web server with several pre-forked listeners can greatly improve response time). However, because any service is allowed to rebind, this option is subject to certain security considerations. Note that by combining this option with ReuseAddressHint, you will also allow your service to rebind an existing shared address. On Unix, this is equivalent to the SO_REUSEADDR socket option. On Windows, this option is ignored.</td></tr>
<tr><td class="topAlign"><tt>QUdpSocket::DontShareAddress</tt></td><td class="topAlign"><tt>0x2</tt></td><td class="topAlign">Bind the address and port exclusively, so that no other services are allowed to rebind. By passing this option to <a href="qudpsocket.html#bind">QUdpSocket::bind</a>(), you are guaranteed that on successs, your service is the only one that listens to the address and port. No services are allowed to rebind, even if they pass ReuseAddressHint. This option provides more security than ShareAddress, but on certain operating systems, it requires you to run the server with administrator privileges. On Unix and Mac OS X, not sharing is the default behavior for binding an address and port, so this option is ignored. On Windows, this option uses the SO_EXCLUSIVEADDRUSE socket option.</td></tr>
<tr><td class="topAlign"><tt>QUdpSocket::ReuseAddressHint</tt></td><td class="topAlign"><tt>0x4</tt></td><td class="topAlign">Provides a hint to <a href="qudpsocket.html">QUdpSocket</a> that it should try to rebind the service even if the address and port are already bound by another socket. On Windows, this is equivalent to the SO_REUSEADDR socket option. On Unix, this option is ignored.</td></tr>
<tr><td class="topAlign"><tt>QUdpSocket::DefaultForPlatform</tt></td><td class="topAlign"><tt>0x0</tt></td><td class="topAlign">The default option for the current platform. On Unix and Mac OS X, this is equivalent to (DontShareAddress + ReuseAddressHint), and on Windows, its equivalent to ShareAddress.</td></tr>
</table>
<p>This enum was introduced or modified in Qt 4.1.</p>
<p>The BindMode type is a typedef for <a href="qflags.html">QFlags</a>&lt;BindFlag&gt;. It stores an OR combination of BindFlag values.</p>
<!-- @@@BindFlag -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QUdpSocket[overload1]$$$QUdpSocketQObject* -->
<h3 class="fn"><a name="QUdpSocket"></a>QUdpSocket::<span class="name">QUdpSocket</span> ( <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Creates a <a href="qudpsocket.html">QUdpSocket</a> object.</p>
<p><i>parent</i> is passed to the <a href="qobject.html">QObject</a> constructor.</p>
<p><b>See also </b><a href="qabstractsocket.html#socketType">socketType</a>().</p>
<!-- @@@QUdpSocket -->
<!-- $$$~QUdpSocket[overload1]$$$~QUdpSocket -->
<h3 class="fn"><a name="dtor.QUdpSocket"></a>QUdpSocket::<span class="name">~QUdpSocket</span> ()<tt> [virtual]</tt></h3>
<p>Destroys the socket, closing the connection if necessary.</p>
<p><b>See also </b><a href="qabstractsocket.html#close">close</a>().</p>
<!-- @@@~QUdpSocket -->
<!-- $$$bind[overload1]$$$bindconstQHostAddress&quint16 -->
<h3 class="fn"><a name="bind"></a><span class="type">bool</span> QUdpSocket::<span class="name">bind</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>address</i>, <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> )</h3>
<p>Binds this socket to the address <i>address</i> and the port <i>port</i>. When bound, the signal <a href="qiodevice.html#readyRead">readyRead</a>() is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.</p>
<p>On success, the functions returns true and the socket enters <a href="qabstractsocket.html#SocketState-enum">BoundState</a>; otherwise it returns false.</p>
<p>The socket is bound using the <a href="qudpsocket.html#BindFlag-enum">DefaultForPlatform</a> <a href="qudpsocket.html#BindFlag-enum">BindMode</a>.</p>
<p><b>See also </b><a href="qudpsocket.html#readDatagram">readDatagram</a>().</p>
<!-- @@@bind -->
<!-- $$$bind$$$bindconstQHostAddress&quint16BindMode -->
<h3 class="fn"><a name="bind-2"></a><span class="type">bool</span> QUdpSocket::<span class="name">bind</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>address</i>, <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i>, <span class="type"><a href="qudpsocket.html#BindFlag-enum">BindMode</a></span> <i>mode</i> )</h3>
<p>This is an overloaded function.</p>
<p>Binds to <i>address</i> on port <i>port</i>, using the <a href="qudpsocket.html#BindFlag-enum">BindMode</a> <i>mode</i>.</p>
<p>This function was introduced in Qt 4.1.</p>
<!-- @@@bind -->
<!-- $$$bind$$$bindquint16 -->
<h3 class="fn"><a name="bind-3"></a><span class="type">bool</span> QUdpSocket::<span class="name">bind</span> ( <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> = 0 )</h3>
<p>This is an overloaded function.</p>
<p>Binds to <a href="qhostaddress.html">QHostAddress</a>:Any on port <i>port</i>.</p>
<!-- @@@bind -->
<!-- $$$bind$$$bindquint16BindMode -->
<h3 class="fn"><a name="bind-4"></a><span class="type">bool</span> QUdpSocket::<span class="name">bind</span> ( <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i>, <span class="type"><a href="qudpsocket.html#BindFlag-enum">BindMode</a></span> <i>mode</i> )</h3>
<p>This is an overloaded function.</p>
<p>Binds to <a href="qhostaddress.html">QHostAddress</a>:Any on port <i>port</i>, using the <a href="qudpsocket.html#BindFlag-enum">BindMode</a> <i>mode</i>.</p>
<p>This function was introduced in Qt 4.1.</p>
<!-- @@@bind -->
<!-- $$$hasPendingDatagrams[overload1]$$$hasPendingDatagrams -->
<h3 class="fn"><a name="hasPendingDatagrams"></a><span class="type">bool</span> QUdpSocket::<span class="name">hasPendingDatagrams</span> () const</h3>
<p>Returns true if at least one datagram is waiting to be read; otherwise returns false.</p>
<p><b>See also </b><a href="qudpsocket.html#pendingDatagramSize">pendingDatagramSize</a>() and <a href="qudpsocket.html#readDatagram">readDatagram</a>().</p>
<!-- @@@hasPendingDatagrams -->
<!-- $$$joinMulticastGroup[overload1]$$$joinMulticastGroupconstQHostAddress& -->
<h3 class="fn"><a name="joinMulticastGroup"></a><span class="type">bool</span> QUdpSocket::<span class="name">joinMulticastGroup</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>groupAddress</i> )</h3>
<p>Joins the the multicast group specified by <i>groupAddress</i> on the default interface chosen by the operating system. The socket must be in <a href="qabstractsocket.html#SocketState-enum">BoundState</a>, otherwise an error occurs.</p>
<p>This function returns true if successful; otherwise it returns false and sets the socket error accordingly.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#leaveMulticastGroup">leaveMulticastGroup</a>().</p>
<!-- @@@joinMulticastGroup -->
<!-- $$$joinMulticastGroup$$$joinMulticastGroupconstQHostAddress&constQNetworkInterface& -->
<h3 class="fn"><a name="joinMulticastGroup-2"></a><span class="type">bool</span> QUdpSocket::<span class="name">joinMulticastGroup</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>groupAddress</i>, const <span class="type"><a href="qnetworkinterface.html">QNetworkInterface</a></span> &amp; <i>iface</i> )</h3>
<p>This is an overloaded function.</p>
<p>Joins the multicast group address <i>groupAddress</i> on the interface <i>iface</i>.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#leaveMulticastGroup">leaveMulticastGroup</a>().</p>
<!-- @@@joinMulticastGroup -->
<!-- $$$leaveMulticastGroup[overload1]$$$leaveMulticastGroupconstQHostAddress& -->
<h3 class="fn"><a name="leaveMulticastGroup"></a><span class="type">bool</span> QUdpSocket::<span class="name">leaveMulticastGroup</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>groupAddress</i> )</h3>
<p>Leaves the multicast group specified by <i>groupAddress</i> on the default interface chosen by the operating system. The socket must be in <a href="qabstractsocket.html#SocketState-enum">BoundState</a>, otherwise an error occurs.</p>
<p>This function returns true if successful; otherwise it returns false and sets the socket error accordingly.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#joinMulticastGroup">joinMulticastGroup</a>().</p>
<!-- @@@leaveMulticastGroup -->
<!-- $$$leaveMulticastGroup$$$leaveMulticastGroupconstQHostAddress&constQNetworkInterface& -->
<h3 class="fn"><a name="leaveMulticastGroup-2"></a><span class="type">bool</span> QUdpSocket::<span class="name">leaveMulticastGroup</span> ( const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>groupAddress</i>, const <span class="type"><a href="qnetworkinterface.html">QNetworkInterface</a></span> &amp; <i>iface</i> )</h3>
<p>This is an overloaded function.</p>
<p>Leaves the multicast group specified by <i>groupAddress</i> on the interface <i>iface</i>.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#joinMulticastGroup">joinMulticastGroup</a>().</p>
<!-- @@@leaveMulticastGroup -->
<!-- $$$multicastInterface[overload1]$$$multicastInterface -->
<h3 class="fn"><a name="multicastInterface"></a><span class="type"><a href="qnetworkinterface.html">QNetworkInterface</a></span> QUdpSocket::<span class="name">multicastInterface</span> () const</h3>
<p>Returns the interface for the outgoing interface for multicast datagrams. This corresponds to the IP_MULTICAST_IF socket option for IPv4 sockets and the IPV6_MULTICAST_IF socket option for IPv6 sockets. If no interface has been previously set, this function returns an invalid <a href="qnetworkinterface.html">QNetworkInterface</a>. The socket must be in <a href="qabstractsocket.html#SocketState-enum">BoundState</a>, otherwise an invalid <a href="qnetworkinterface.html">QNetworkInterface</a> is returned.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#setMulticastInterface">setMulticastInterface</a>().</p>
<!-- @@@multicastInterface -->
<!-- $$$pendingDatagramSize[overload1]$$$pendingDatagramSize -->
<h3 class="fn"><a name="pendingDatagramSize"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QUdpSocket::<span class="name">pendingDatagramSize</span> () const</h3>
<p>Returns the size of the first pending UDP datagram. If there is no datagram available, this function returns -1.</p>
<p><b>See also </b><a href="qudpsocket.html#hasPendingDatagrams">hasPendingDatagrams</a>() and <a href="qudpsocket.html#readDatagram">readDatagram</a>().</p>
<!-- @@@pendingDatagramSize -->
<!-- $$$readDatagram[overload1]$$$readDatagramchar*qint64QHostAddress*quint16* -->
<h3 class="fn"><a name="readDatagram"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QUdpSocket::<span class="name">readDatagram</span> ( <span class="type">char</span> * <i>data</i>, <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>maxSize</i>, <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> * <i>address</i> = 0, <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> * <i>port</i> = 0 )</h3>
<p>Receives a datagram no larger than <i>maxSize</i> bytes and stores it in <i>data</i>. The sender's host address and port is stored in *<i>address</i> and *<i>port</i> (unless the pointers are 0).</p>
<p>Returns the size of the datagram on success; otherwise returns -1.</p>
<p>If <i>maxSize</i> is too small, the rest of the datagram will be lost. To avoid loss of data, call <a href="qudpsocket.html#pendingDatagramSize">pendingDatagramSize</a>() to determine the size of the pending datagram before attempting to read it. If <i>maxSize</i> is 0, the datagram will be discarded.</p>
<p><b>See also </b><a href="qudpsocket.html#writeDatagram">writeDatagram</a>(), <a href="qudpsocket.html#hasPendingDatagrams">hasPendingDatagrams</a>(), and <a href="qudpsocket.html#pendingDatagramSize">pendingDatagramSize</a>().</p>
<!-- @@@readDatagram -->
<!-- $$$setMulticastInterface[overload1]$$$setMulticastInterfaceconstQNetworkInterface& -->
<h3 class="fn"><a name="setMulticastInterface"></a><span class="type">void</span> QUdpSocket::<span class="name">setMulticastInterface</span> ( const <span class="type"><a href="qnetworkinterface.html">QNetworkInterface</a></span> &amp; <i>iface</i> )</h3>
<p>Sets the outgoing interface for multicast datagrams to the interface <i>iface</i>. This corresponds to the IP_MULTICAST_IF socket option for IPv4 sockets and the IPV6_MULTICAST_IF socket option for IPv6 sockets. The socket must be in <a href="qabstractsocket.html#SocketState-enum">BoundState</a>, otherwise this function does nothing.</p>
<p>This function was introduced in Qt 4.8.</p>
<p><b>See also </b><a href="qudpsocket.html#multicastInterface">multicastInterface</a>(), <a href="qudpsocket.html#joinMulticastGroup">joinMulticastGroup</a>(), and <a href="qudpsocket.html#leaveMulticastGroup">leaveMulticastGroup</a>().</p>
<!-- @@@setMulticastInterface -->
<!-- $$$writeDatagram[overload1]$$$writeDatagramconstchar*qint64constQHostAddress&quint16 -->
<h3 class="fn"><a name="writeDatagram"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QUdpSocket::<span class="name">writeDatagram</span> ( const <span class="type">char</span> * <i>data</i>, <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>size</i>, const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>address</i>, <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> )</h3>
<p>Sends the datagram at <i>data</i> of size <i>size</i> to the host address <i>address</i> at port <i>port</i>. Returns the number of bytes sent on success; otherwise returns -1.</p>
<p>Datagrams are always written as one block. The maximum size of a datagram is highly platform-dependent, but can be as low as 8192 bytes. If the datagram is too large, this function will return -1 and <a href="qabstractsocket.html#error">error</a>() will return <a href="qabstractsocket.html#SocketError-enum">DatagramTooLargeError</a>.</p>
<p>Sending datagrams larger than 512 bytes is in general disadvised, as even if they are sent successfully, they are likely to be fragmented by the IP layer before arriving at their final destination.</p>
<p><b>Warning:</b> In S60 5.0 and earlier versions, the writeDatagram return value is not reliable for large datagrams.</p>
<p><b>Warning:</b> Calling this function on a connected UDP socket may result in an error and no packet being sent. If you are using a connected socket, use <a href="qiodevice.html#write">write</a>() to send datagrams.</p>
<p><b>See also </b><a href="qudpsocket.html#readDatagram">readDatagram</a>() and <a href="qiodevice.html#write">write</a>().</p>
<!-- @@@writeDatagram -->
<!-- $$$writeDatagram$$$writeDatagramconstQByteArray&constQHostAddress&quint16 -->
<h3 class="fn"><a name="writeDatagram-2"></a><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QUdpSocket::<span class="name">writeDatagram</span> ( const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp; <i>datagram</i>, const <span class="type"><a href="qhostaddress.html">QHostAddress</a></span> &amp; <i>host</i>, <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>port</i> )</h3>
<p>This is an overloaded function.</p>
<p>Sends the datagram <i>datagram</i> to the host address <i>host</i> and at port <i>port</i>.</p>
<!-- @@@writeDatagram -->
</div>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      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.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>