Qt 4.8
qudpsocket.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QUDPSOCKET_H
43 #define QUDPSOCKET_H
44 
45 #include <QtNetwork/qabstractsocket.h>
46 #include <QtNetwork/qhostaddress.h>
47 
49 
51 
52 QT_MODULE(Network)
53 
54 #ifndef QT_NO_UDPSOCKET
55 
56 class QNetworkInterface;
57 class QUdpSocketPrivate;
58 
60 {
61  Q_OBJECT
62 public:
63  enum BindFlag {
64  DefaultForPlatform = 0x0,
65  ShareAddress = 0x1,
66  DontShareAddress = 0x2,
67  ReuseAddressHint = 0x4
68  };
69  Q_DECLARE_FLAGS(BindMode, BindFlag)
70 
71  explicit QUdpSocket(QObject *parent = 0);
72  virtual ~QUdpSocket();
73 
74  bool bind(const QHostAddress &address, quint16 port);
75  bool bind(quint16 port = 0);
76  bool bind(const QHostAddress &address, quint16 port, BindMode mode);
77  bool bind(quint16 port, BindMode mode);
78  // ### Qt 5: Merge the bind functions
79 
80 #ifndef QT_NO_NETWORKINTERFACE
81  bool joinMulticastGroup(const QHostAddress &groupAddress);
82  bool joinMulticastGroup(const QHostAddress &groupAddress,
83  const QNetworkInterface &iface);
84  bool leaveMulticastGroup(const QHostAddress &groupAddress);
85  bool leaveMulticastGroup(const QHostAddress &groupAddress,
86  const QNetworkInterface &iface);
87 
88  QNetworkInterface multicastInterface() const;
89  void setMulticastInterface(const QNetworkInterface &iface);
90 #endif
91 
92  bool hasPendingDatagrams() const;
93  qint64 pendingDatagramSize() const;
94  qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host = 0, quint16 *port = 0);
95  qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &host, quint16 port);
96  inline qint64 writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
97  { return writeDatagram(datagram.constData(), datagram.size(), host, port); }
98 
99 private:
102 };
103 
104 Q_DECLARE_OPERATORS_FOR_FLAGS(QUdpSocket::BindMode)
105 
106 #endif // QT_NO_UDPSOCKET
107 
109 
111 
112 #endif // QUDPSOCKET_H
qint64 writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
Sends the datagram datagram to the host address host and at port port.
Definition: qudpsocket.h:96
The QUdpSocket class provides a UDP socket.
Definition: qudpsocket.h:59
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
BindFlag
This enum describes the different flags you can pass to modify the behavior of QUdpSocket::bind().
Definition: qudpsocket.h:63
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
#define Q_NETWORK_EXPORT
Definition: qglobal.h:1452
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QNetworkInterface class provides a listing of the host&#39;s IP addresses and network interfaces...
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
#define QT_END_HEADER
Definition: qglobal.h:137
The QAbstractSocket class provides the base functionality common to all socket types.