Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtNetwork.QUdpSocket Class Reference

The QUdpSocket class provides a UDP socket. More...

Inheritance diagram for QtNetwork.QUdpSocket:
Collaboration diagram for QtNetwork.QUdpSocket:

Public Types

enum  BindFlag { DefaultForPlatform = 0, DontShareAddress = 2, ReuseAddressHint = 4, ShareAddress = 1 }
  More...
 
- Public Types inherited from QtNetwork.QAbstractSocket
enum  NetworkLayerProtocol { IPv4Protocol = 0, IPv6Protocol = 1, UnknownNetworkLayerProtocol = -1 }
  More...
 
enum  SocketError {
  AddressInUseError = 8, ConnectionRefusedError = 0, DatagramTooLargeError = 6, HostNotFoundError = 2,
  NetworkError = 7, ProxyAuthenticationRequiredError = 12, ProxyConnectionClosedError = 15, ProxyConnectionRefusedError = 14,
  ProxyConnectionTimeoutError = 16, ProxyNotFoundError = 17, ProxyProtocolError = 18, RemoteHostClosedError = 1,
  SocketAccessError = 3, SocketAddressNotAvailableError = 9, SocketResourceError = 4, SocketTimeoutError = 5,
  SslHandshakeFailedError = 13, UnfinishedSocketOperationError = 11, UnknownSocketError = -1, UnsupportedSocketOperationError = 10
}
  More...
 
enum  SocketOption { KeepAliveOption = 1, LowDelayOption = 0, MulticastLoopbackOption = 3, MulticastTtlOption = 2 }
  More...
 
enum  SocketState {
  BoundState = 4, ClosingState = 6, ConnectedState = 3, ConnectingState = 2,
  HostLookupState = 1, ListeningState = 5, UnconnectedState = 0
}
  More...
 
enum  SocketType { TcpSocket = 0, UdpSocket = 1, UnknownSocketType = -1 }
  More...
 
- Public Types inherited from QtCore.QIODevice
enum  OpenModeFlag {
  Append = 4, NotOpen = 0, ReadOnly = 1, ReadWrite = 3,
  Text = 16, Truncate = 8, Unbuffered = 32, WriteOnly = 2
}
  More...
 

Public Member Functions

 QUdpSocket (QObject parent=null)
 
 
override void CreateProxy ()
 
new bool Bind (QHostAddress address, ushort port)
 
 
new bool Bind (QHostAddress address, ushort port, QUdpSocket.BindFlag mode)
 
 
new bool Bind (ushort port=0)
 
 
new bool Bind (ushort port, QUdpSocket.BindFlag mode)
 
 
new bool HasPendingDatagrams ()
 
 
new bool JoinMulticastGroup (QHostAddress groupAddress)
 
 
new bool JoinMulticastGroup (QHostAddress groupAddress, QNetworkInterface iface)
 
 
new bool LeaveMulticastGroup (QHostAddress groupAddress)
 
 
new bool LeaveMulticastGroup (QHostAddress groupAddress, QNetworkInterface iface)
 
 
new long PendingDatagramSize ()
 
 
new long ReadDatagram (Pointer< sbyte > data, long maxlen, QHostAddress host=null)
 
 
new long ReadDatagram (Pointer< sbyte > data, long maxlen, QHostAddress host, ref ushort port)
 
 
new long WriteDatagram (QByteArray datagram, QHostAddress host, ushort port)
 
 
new long WriteDatagram (string data, long len, QHostAddress host, ushort port)
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtNetwork.QAbstractSocket
 QAbstractSocket (QAbstractSocket.SocketType socketType, QObject parent)
 
 
new void Abort ()
 
 
override bool AtEnd ()
 
 
override long BytesAvailable ()
 
 
override long BytesToWrite ()
 
 
override bool CanReadLine ()
 
 
override void Close ()
 
 
new void ConnectToHost (QHostAddress address, ushort port, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.ReadWrite)
 
 
new void ConnectToHost (string hostName, ushort port, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.ReadWrite)
 
 
new void DisconnectFromHost ()
 
 
new QAbstractSocket.SocketError OnError ()
 
 
new bool Flush ()
 
 
override bool IsSequential ()
 
 
new bool IsValid ()
 
 
new QHostAddress LocalAddress ()
 
 
new ushort LocalPort ()
 
 
new QHostAddress PeerAddress ()
 
 
new string PeerName ()
 
 
new ushort PeerPort ()
 
 
new bool SetSocketDescriptor (int socketDescriptor, QAbstractSocket.SocketState state=QAbstractSocket.SocketState.ConnectedState, QIODevice.OpenModeFlag openMode=QIODevice.OpenModeFlag.ReadWrite)
 
 
new void SetSocketOption (QAbstractSocket.SocketOption option, object value)
 
 
new int SocketDescriptor ()
 
 
new object socketOption (QAbstractSocket.SocketOption option)
 
 
new QAbstractSocket.SocketType socketType ()
 
 
new QAbstractSocket.SocketState State ()
 
 
override bool WaitForBytesWritten (int msecs=30000)
 
 
new bool WaitForConnected (int msecs=30000)
 
 
new bool WaitForDisconnected (int msecs=30000)
 
 
override bool WaitForReadyRead (int msecs=30000)
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QIODevice
 QIODevice ()
 
 
 QIODevice (QObject parent)
 
 
new string ErrorString ()
 
 
new bool GetChar (Pointer< sbyte > c)
 
 
new bool IsOpen ()
 
 
new bool IsReadable ()
 
 
new bool IsTextModeEnabled ()
 
 
new bool IsWritable ()
 
 
virtual bool Open (QIODevice.OpenModeFlag mode)
 
 
new QIODevice.OpenModeFlag OpenMode ()
 
 
new QByteArray Peek (long maxlen)
 
 
new long Peek (Pointer< sbyte > data, long maxlen)
 
 
virtual long Pos ()
 
 
new bool PutChar (sbyte c)
 
 
new QByteArray Read (long maxlen)
 
 
new long Read (Pointer< sbyte > data, long maxlen)
 
 
new QByteArray ReadAll ()
 
 
new QByteArray ReadLine (long maxlen=0)
 
 
new long ReadLine (Pointer< sbyte > data, long maxlen)
 
 
virtual bool Reset ()
 
 
virtual bool Seek (long pos)
 
 
new void SetTextModeEnabled (bool enabled)
 
 
virtual long Size ()
 
 
new void UngetChar (sbyte c)
 
 
new long Write (QByteArray data)
 
 
new long Write (string data)
 
 
new long Write (string data, long len)
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QObject
 QObject (QObject parent=null)
 
 
new bool BlockSignals (bool b)
 
 
new
System.Collections.Generic.List
< QObject
Children ()
 
 
new bool Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
new void DeleteLater ()
 
 
new bool Disconnect (QObject receiver, string member=null)
 
 
new bool Disconnect (string signal=null, QObject receiver=null, string member=null)
 
 
new void DumpObjectInfo ()
 
 
new void DumpObjectTree ()
 
 
new
System.Collections.Generic.List
< QByteArray
DynamicPropertyNames ()
 
 
virtual bool OnEvent (QEvent arg1)
 
 
virtual bool EventFilter (QObject arg1, QEvent arg2)
 
 
new bool Inherits (string classname)
 
 
new void InstallEventFilter (QObject arg1)
 
 
new bool IsWidgetType ()
 
 
new void KillTimer (int id)
 
 
new object Property (string name)
 
 
new void RemoveEventFilter (QObject arg1)
 
 
new bool SetProperty (string name, object value)
 
 
new void SetUserData (uint id, QObjectUserData data)
 
new bool SignalsBlocked ()
 
 
new int StartTimer (int interval)
 
 
new QObjectUserData UserData (uint id)
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.Qt
delegate QTextStream FuncQTextStreamQTextStream (QTextStream qTextStream)
 
delegate string FuncStringQByteArray (QByteArray qByteArray)
 
delegate QByteArray FuncQByteArrayString (string @string)
 
delegate void ActionQtMsgTypeString (QtMsgType qtMsgType, string @string)
 
delegate QObject FuncQObject ()
 

Static Public Member Functions

static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtNetwork.QAbstractSocket
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QIODevice
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QObject
static bool Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
static bool Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection)
 
 
static bool Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member)
 
 
static bool Disconnect (QObject sender, string signal, QObject receiver, string member)
 
 
static uint RegisterUserData ()
 
static string Tr (string s, string c=null)
 
 
static string Tr (string s, string c, int n)
 
 
static string TrUtf8 (string s, string c=null)
 
 
static string TrUtf8 (string s, string c, int n)
 
 
- Static Public Member Functions inherited from QtCore.Qt
static QDataStream Write (QDataStream s, object p)
 
static QDataStream Write (QDataStream arg1, QSizeF arg2)
 
static QTextStream Write (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Write (QDataStream arg1, QPoint arg2)
 
static QDataStream Write (QDataStream arg1, QLineF arg2)
 
static QDataStream Write (QDataStream arg1, QPointF arg2)
 
static QDataStream Write (QDataStream arg1, QChar arg2)
 
static QDataStream Write (QDataStream arg1, QByteArray arg2)
 
static QDataStream Write (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Write (QDataStream arg1, QRectF arg2)
 
static QDataStream Write (QDataStream arg1, QDateTime arg2)
 
static QDataStream Write (QDataStream arg1, QUrl arg2)
 
static QDataStream Write (QDataStream arg1, QTime arg2)
 
static QDataStream Write (QDataStream arg1, QLocale arg2)
 
static QDataStream Write (QDataStream arg1, QBitArray arg2)
 
static QDataStream Write (QDataStream arg1, QUuid arg2)
 
static QDataStream Write (QDataStream arg1, QLine arg2)
 
static QDataStream Write (QDataStream arg1, QDate arg2)
 
static QDataStream Write (QDataStream @out, QRegExp regExp)
 
static QDataStream Write (QDataStream arg1, QRect arg2)
 
static QDataStream Write (QDataStream arg1, QSize arg2)
 
static QDataStream Write (QDataStream s, QVariant.Type p)
 
static QDataStream Write (QDataStream arg1, string arg2)
 
static QDataStream Write (QDataStream @out, System.Collections.Generic.List< string > list)
 
static QDataStream Read (QDataStream arg1, QChar arg2)
 
static QDataStream Read (QDataStream arg1, QLocale arg2)
 
static QDataStream Read (QDataStream arg1, QRect arg2)
 
static QDataStream Read (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Read (QDataStream arg1, QDate arg2)
 
static QDataStream Read (QDataStream arg1, QUrl arg2)
 
static QDataStream Read (QDataStream arg1, QUuid arg2)
 
static QTextStream Read (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Read (QDataStream arg1, QLineF arg2)
 
static QDataStream Read (QDataStream arg1, QRectF arg2)
 
static QDataStream Read (QDataStream arg1, QPointF arg2)
 
static QDataStream Read (QDataStream arg1, QLine arg2)
 
static QDataStream Read (QDataStream arg1, QBitArray arg2)
 
static QDataStream Read (QDataStream arg1, QSize arg2)
 
static QDataStream Read (QDataStream arg1, QDateTime arg2)
 
static QDataStream Read (QDataStream arg1, QTime arg2)
 
static QDataStream Read (QDataStream arg1, QPoint arg2)
 
static QDataStream Read (QDataStream @in, QRegExp regExp)
 
static QDataStream Read (QDataStream s, object p)
 
static QDataStream Read (QDataStream arg1, QByteArray arg2)
 
static QDataStream Read (QDataStream arg1, QSizeF arg2)
 
static QDataStream Read (QDataStream arg1, string arg2)
 
static QDataStream Read (QDataStream s, QVariant.Type p)
 
static QDataStream Read (QDataStream @in, System.Collections.Generic.List< string > list)
 
static double qAcos (double v)
 
static void qAddPostRoutine (System.Action arg1)
 
static string qAppName ()
 
static double qAsin (double v)
 
static double qAtan (double v)
 
static double qAtan2 (double x, double y)
 
static void qBadAlloc ()
 
static int qCeil (double v)
 
static ushort qChecksum (string s, uint len)
 
static QByteArray qCompress (QByteArray data)
 
static QByteArray qCompress (QByteArray data, int compressionLevel=-1)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1)
 
static double qCos (double v)
 
static double qExp (double v)
 
static double qFabs (double v)
 
static double qFastCos (double x)
 
static double qFastSin (double x)
 
static string qFlagLocation (string method)
 
static int qFloor (double v)
 
static bool qFuzzyCompare (double p1, double p2)
 
static bool qFuzzyCompare (float p1, float p2)
 
static bool qFuzzyIsNull (double d)
 
static bool qFuzzyIsNull (float f)
 
static uint qHash (QBitArray key)
 
static uint qHash (QChar key)
 
static uint qHash (QStringRef key)
 
static uint qHash (QUrl url)
 
static uint qHash (QPersistentModelIndex index)
 
static uint qHash (QByteArray key)
 
static uint qHash (QModelIndex index)
 
static uint qHash (uint key)
 
static uint qHash (sbyte key)
 
static uint qHash (byte key)
 
static uint qHash (short key)
 
static uint qHash (NativeLong key)
 
static uint qHash (ushort key)
 
static uint qHash (long key)
 
static uint qHash (ulong key)
 
static uint qHash (int key)
 
static uint qHash (string key)
 
static uint qHash (NativeULong key)
 
static double qInf ()
 
static Qt.ActionQtMsgTypeString qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1)
 
static int qIntCast (float f)
 
static int qIntCast (double f)
 
static bool qIsFinite (double d)
 
static bool qIsFinite (float f)
 
static bool qIsInf (float f)
 
static bool qIsInf (double d)
 
static bool qIsNaN (float f)
 
static bool qIsNaN (double d)
 
static bool qIsNull (float f)
 
static bool qIsNull (double d)
 
static double qLn (double v)
 
static double qPow (double x, double y)
 
static double qQNaN ()
 
static void qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function)
 
static void qRemovePostRoutine (System.Action arg1)
 
static int qRound (double d)
 
static long qRound64 (double d)
 
static double qSNaN ()
 
static bool qSharedBuild ()
 
static double qSin (double v)
 
static double qSqrt (double v)
 
static bool qStringComparisonHelper (QStringRef s1, string s2)
 
static double qTan (double v)
 
static QByteArray qUncompress (QByteArray data)
 
static QByteArray qUncompress (Pointer< byte > data, int nbytes)
 
static string qVersion ()
 
static void Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size)
 
static QByteArray Qgetenv (string varName)
 
static bool Qputenv (string varName, QByteArray value)
 
static int Qrand ()
 
static void Qsrand (uint seed)
 
static int Qstrcmp (QByteArray str1, QByteArray str2)
 
static int Qstrcmp (QByteArray str1, string str2)
 
static int Qstrcmp (string str1, QByteArray str2)
 
static int Qstrcmp (string str1, string str2)
 
static Pointer< sbyte > Qstrcpy (Pointer< sbyte > dst, string src)
 
static Pointer< sbyte > Qstrdup (string arg1)
 
static int Qstricmp (string arg1, string arg2)
 
static uint Qstrlen (string str)
 
static int Qstrncmp (string str1, string str2, uint len)
 
static Pointer< sbyte > Qstrncpy (Pointer< sbyte > dst, string src, uint len)
 
static int Qstrnicmp (string arg1, string arg2, uint len)
 
static uint Qstrnlen (string str, uint maxlen)
 
static string QtTrId (string id, int n=-1)
 

Protected Member Functions

 QUdpSocket (System.Type dummy)
 
- Protected Member Functions inherited from QtNetwork.QAbstractSocket
 QAbstractSocket (System.Type dummy)
 
new void ConnectToHostImplementation (string hostName, ushort port, QIODevice.OpenModeFlag mode=QIODevice.OpenModeFlag.ReadWrite)
 
 
new void OnConnected ()
 
 
new void DisconnectFromHostImplementation ()
 
 
new void OnDisconnected ()
 
 
new void OnError (QAbstractSocket.SocketError arg1)
 
 
new void OnHostFound ()
 
 
new void OnProxyAuthenticationRequired (QNetworkProxy proxy, QAuthenticator authenticator)
 
 
override long ReadData (Pointer< sbyte > data, long maxlen)
 
 
override long ReadLineData (Pointer< sbyte > data, long maxlen)
 
 
new void SetLocalAddress (QHostAddress address)
 
 
new void SetLocalPort (ushort port)
 
 
new void SetPeerAddress (QHostAddress address)
 
 
new void SetPeerName (string name)
 
 
new void SetPeerPort (ushort port)
 
 
new void SetSocketError (QAbstractSocket.SocketError socketError)
 
 
new void SetSocketState (QAbstractSocket.SocketState state)
 
 
new void OnStateChanged (QAbstractSocket.SocketState arg1)
 
 
override long WriteData (string data, long len)
 
 
- Protected Member Functions inherited from QtCore.QIODevice
 QIODevice (System.Type dummy)
 
new void OnAboutToClose ()
 
 
new void OnBytesWritten (long bytes)
 
 
new void OnReadChannelFinished ()
 
 
new void OnReadyRead ()
 
 
new void SetErrorString (string errorString)
 
 
new void SetOpenMode (QIODevice.OpenModeFlag openMode)
 
 
- Protected Member Functions inherited from QtCore.QObject
 QObject (System.Type dummy)
 
virtual void OnChildEvent (QChildEvent arg1)
 
 
virtual void ConnectNotify (string signal)
 
 
virtual void OnCustomEvent (QEvent arg1)
 
 
new void OnDestroyed (QObject arg1=null)
 
 
virtual void DisconnectNotify (string signal)
 
 
new int Receivers (string signal)
 
 
new QObject Sender ()
 
 
new int SenderSignalIndex ()
 
 
virtual void OnTimerEvent (QTimerEvent arg1)
 
 

Properties

new QNetworkInterface MulticastInterface [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQUdpSocketSignals Emit [get]
 
- Properties inherited from QtNetwork.QAbstractSocket
Slot HostFound
 
 
Slot Connected
 
 
Slot Disconnected
 
 
Slot< QAbstractSocket.SocketStateStateChanged
 
 
Slot< QAbstractSocket.SocketErrorError
 
 
Slot< QNetworkProxy,
QAuthenticator
ProxyAuthenticationRequired
 
 
Slot ConnectionClosed
 
Slot DelayedCloseFinished
 
new QNetworkProxy Proxy [get, set]
 
 
new long ReadBufferSize [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQAbstractSocketSignals Emit [get]
 
- Properties inherited from QtCore.QIODevice
Slot ReadyRead
 
 
Slot< System.Int64 > BytesWritten
 
 
Slot AboutToClose
 
 
Slot ReadChannelFinished
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQIODeviceSignals Emit [get]
 
- Properties inherited from QtCore.QObject
virtual EventHandler
< QEventArgs< QChildEvent > > 
ChildEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
CustomEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
Event
 
 
virtual EventHandler
< QEventArgs< QTimerEvent > > 
TimerEvent
 
 
Slot< QObjectDestroyedQObject
 
Slot Destroyed
 
 
new QObject Parent [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
new string ObjectName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
 
static new QMetaObject StaticQtMetaObject [get]
 
new IQObjectSignals Emit [get]
 

Additional Inherited Members

- Protected Attributes inherited from QtCore.QObject
object Q_EMIT = null
 
SmokeInvocation interceptor
 
readonly List< QEventHandler > eventFilters = new List<QEventHandler>()
 

Detailed Description

The QUdpSocket class provides a UDP socket.

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 QAbstractSocket that allows you to send and receive UDP datagrams.

The most common way to use this class is to bind to an address and port using bind(), then call writeDatagram() and readDatagram() to transfer data. If you want to use the standard QIODevice functions read(), readLine(), write(), etc., you must first connect the socket directly to a peer by calling connectToHost().

The socket emits the bytesWritten() signal every time a datagram is written to the network. If you just want to send datagrams, you don't need to call bind().

The readyRead() signal is emitted whenever datagrams arrive. In that case, hasPendingDatagrams() returns true. Call pendingDatagramSize() to obtain the size of the first pending datagram, and readDatagram() to read it.

Note: An incoming datagram should be read when you receive the readyRead() signal, otherwise this signal will not be emitted for the next datagram.

Example:

void Server::initSocket()

{

udpSocket = new QUdpSocket(this);

udpSocket->bind(QHostAddress::LocalHost, 7755);

connect(udpSocket, SIGNAL(readyRead()),

this, SLOT(readPendingDatagrams()));

}

void Server::readPendingDatagrams()

{

while (udpSocket->hasPendingDatagrams()) {

QByteArray datagram;

datagram.resize(udpSocket->pendingDatagramSize());

QHostAddress sender;

quint16 senderPort;

udpSocket->readDatagram(datagram.data(), datagram.size(),

&sender, &senderPort);

processTheDatagram(datagram);

}

}

QUdpSocket also supports UDP multicast. Use joinMulticastGroup() and leaveMulticastGroup() to control group membership, and QAbstractSocket::MulticastTtlOption and QAbstractSocket::MulticastLoopbackOption to set the TTL and loopback socket options. Use setMulticastInterface() to control the outgoing interface for multicast datagrams, and multicastInterface() to query it.

With QUdpSocket, you can also establish a virtual connection to a UDP server using connectToHost() and then use read() and write() to exchange datagrams without specifying the receiver for each datagram.

The Broadcast Sender, Broadcast Receiver, Multicast Sender, and Multicast Receiver examples illustrate how to use QUdpSocket in applications.

Symbian Platform Security Requirements

On Symbian, processes which use this class must have the NetworkServices platform security capability. If the client process lacks this capability, operations will result in a panic.

Platform security capabilities are added via the TARGET.CAPABILITY qmake variable.

See also QTcpSocket.

Member Enumeration Documentation

This enum describes the different flags you can pass to modify the behavior of QUdpSocket::bind().

Note: 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.

This enum was introduced or modified in Qt 4.1.

Enumerator:
DefaultForPlatform 

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.

DontShareAddress 

Bind the address and port exclusively, so that no other services are allowed to rebind. By passing this option to QUdpSocket::bind(), 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.

ReuseAddressHint 

Provides a hint to QUdpSocket 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.

ShareAddress 

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., 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.

Constructor & Destructor Documentation

QtNetwork.QUdpSocket.QUdpSocket ( System.Type  dummy)
protected
QtNetwork.QUdpSocket.QUdpSocket ( QObject  parent = null)

Creates a QUdpSocket object.

parent is passed to the QObject constructor.

See also socketType().

Member Function Documentation

new bool QtNetwork.QUdpSocket.Bind ( QHostAddress  address,
ushort  port 
)

Binds this socket to the address address and the port port. When bound, the signal readyRead() is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.

On success, the functions returns true and the socket enters BoundState; otherwise it returns false.

The socket is bound using the DefaultForPlatform BindMode.

See also readDatagram().

new bool QtNetwork.QUdpSocket.Bind ( QHostAddress  address,
ushort  port,
QUdpSocket.BindFlag  mode 
)

Binds this socket to the address address and the port port. When bound, the signal readyRead() is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.

On success, the functions returns true and the socket enters BoundState; otherwise it returns false.

The socket is bound using the DefaultForPlatform BindMode.

See also readDatagram().

new bool QtNetwork.QUdpSocket.Bind ( ushort  port = 0)

Binds this socket to the address address and the port port. When bound, the signal readyRead() is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.

On success, the functions returns true and the socket enters BoundState; otherwise it returns false.

The socket is bound using the DefaultForPlatform BindMode.

See also readDatagram().

new bool QtNetwork.QUdpSocket.Bind ( ushort  port,
QUdpSocket.BindFlag  mode 
)

Binds this socket to the address address and the port port. When bound, the signal readyRead() is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.

On success, the functions returns true and the socket enters BoundState; otherwise it returns false.

The socket is bound using the DefaultForPlatform BindMode.

See also readDatagram().

override void QtNetwork.QUdpSocket.CreateProxy ( )
virtual

Reimplemented from QtNetwork.QAbstractSocket.

new void QtNetwork.QUdpSocket.Dispose ( )
new bool QtNetwork.QUdpSocket.HasPendingDatagrams ( )

Returns true if at least one datagram is waiting to be read; otherwise returns false.

See also pendingDatagramSize() and readDatagram().

new bool QtNetwork.QUdpSocket.JoinMulticastGroup ( QHostAddress  groupAddress)

Joins the the multicast group specified by groupAddress on the default interface chosen by the operating system. The socket must be in BoundState, otherwise an error occurs.

This function returns true if successful; otherwise it returns false and sets the socket error accordingly.

This function was introduced in Qt 4.8.

See also leaveMulticastGroup().

new bool QtNetwork.QUdpSocket.JoinMulticastGroup ( QHostAddress  groupAddress,
QNetworkInterface  iface 
)

This is an overloaded function.

Joins the multicast group address groupAddress on the interface iface.

This function was introduced in Qt 4.8.

See also leaveMulticastGroup().

new bool QtNetwork.QUdpSocket.LeaveMulticastGroup ( QHostAddress  groupAddress)

Leaves the multicast group specified by groupAddress on the default interface chosen by the operating system. The socket must be in BoundState, otherwise an error occurs.

This function returns true if successful; otherwise it returns false and sets the socket error accordingly.

This function was introduced in Qt 4.8.

See also joinMulticastGroup().

new bool QtNetwork.QUdpSocket.LeaveMulticastGroup ( QHostAddress  groupAddress,
QNetworkInterface  iface 
)

This is an overloaded function.

Leaves the multicast group specified by groupAddress on the interface iface.

This function was introduced in Qt 4.8.

See also joinMulticastGroup().

new long QtNetwork.QUdpSocket.PendingDatagramSize ( )

Returns the size of the first pending UDP datagram. If there is no datagram available, this function returns -1.

See also hasPendingDatagrams() and readDatagram().

new long QtNetwork.QUdpSocket.ReadDatagram ( Pointer< sbyte >  data,
long  maxlen,
QHostAddress  host = null 
)

Receives a datagram no larger than maxSize bytes and stores it in data. The sender's host address and port is stored in *address and *port (unless the pointers are 0).

Returns the size of the datagram on success; otherwise returns -1.

If maxSize is too small, the rest of the datagram will be lost. To avoid loss of data, call pendingDatagramSize() to determine the size of the pending datagram before attempting to read it. If maxSize is 0, the datagram will be discarded.

See also writeDatagram(), hasPendingDatagrams(), and pendingDatagramSize().

new long QtNetwork.QUdpSocket.ReadDatagram ( Pointer< sbyte >  data,
long  maxlen,
QHostAddress  host,
ref ushort  port 
)

Receives a datagram no larger than maxSize bytes and stores it in data. The sender's host address and port is stored in *address and *port (unless the pointers are 0).

Returns the size of the datagram on success; otherwise returns -1.

If maxSize is too small, the rest of the datagram will be lost. To avoid loss of data, call pendingDatagramSize() to determine the size of the pending datagram before attempting to read it. If maxSize is 0, the datagram will be discarded.

See also writeDatagram(), hasPendingDatagrams(), and pendingDatagramSize().

static string QtNetwork.QUdpSocket.Tr ( string  s,
string  c = null 
)
static
static string QtNetwork.QUdpSocket.Tr ( string  s,
string  c,
int  n 
)
static
static string QtNetwork.QUdpSocket.TrUtf8 ( string  s,
string  c = null 
)
static
static string QtNetwork.QUdpSocket.TrUtf8 ( string  s,
string  c,
int  n 
)
static
new long QtNetwork.QUdpSocket.WriteDatagram ( QByteArray  datagram,
QHostAddress  host,
ushort  port 
)

Sends the datagram at data of size size to the host address address at port port. Returns the number of bytes sent on success; otherwise returns -1.

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 error() will return DatagramTooLargeError.

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.

Warning: In S60 5.0 and earlier versions, the writeDatagram return value is not reliable for large datagrams.

Warning: 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 write() to send datagrams.

See also readDatagram() and write().

new long QtNetwork.QUdpSocket.WriteDatagram ( string  data,
long  len,
QHostAddress  host,
ushort  port 
)

Sends the datagram at data of size size to the host address address at port port. Returns the number of bytes sent on success; otherwise returns -1.

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 error() will return DatagramTooLargeError.

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.

Warning: In S60 5.0 and earlier versions, the writeDatagram return value is not reliable for large datagrams.

Warning: 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 write() to send datagrams.

See also readDatagram() and write().

Property Documentation

new IQUdpSocketSignals QtNetwork.QUdpSocket.Emit
getprotected
new QNetworkInterface QtNetwork.QUdpSocket.MulticastInterface
getset

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 QNetworkInterface. The socket must be in BoundState, otherwise an invalid QNetworkInterface is returned.

This function was introduced in Qt 4.8.

Sets the outgoing interface for multicast datagrams to the interface iface. 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 BoundState, otherwise this function does nothing.

This function was introduced in Qt 4.8.

new QMetaObject QtNetwork.QUdpSocket.StaticMetaObject
staticget