qt network!

        The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.

QNetworkInterface  one network interface attached to the host where the program is being run. Each network interface may contain zero or more IP addresses, each of which is optionally associated with a netmask and/or a broadcast address. The list of such trios can be obtained with addressEntries(). Alternatively, when the netmask or the broadcast addresses aren't necessary, use theallAddresses() convenience function to obtain just the IP addresses.

QNetworkInterface also reports the interface's hardware address with hardwareAddress().

Not all operating systems support reporting all features. Only the IPv4 addresses are features to be listed by this class in all platforms. In particular, IPv6 address listing is only supported on Windows XP and more recent versions, Linux, MacOS X and the BSDs.

   这个QNetworkinterdace类提供了主机的ip地址和网络的接口!QNetworkInterface 表现了一个附加于程序运行的主机的网络接口。每一个网络接口的含有0个或多个ip地址,与子网掩码和广播地址相关的地址。可选择的,当子网掩码或网络广播地址不是很有必要,用allAddresses()非常方便得到所有地址。当然也可以得到接口的硬件的mac地址。不是所有的操作系统支持所有的。所有的平台都支持ip4,ip6就不是了!

      也就是说QNetWorkInterface用于查询主机上所有的Ip地址和网络接口

       这下来说一下 QHostAddress这个类把,

the QHostAddress class provides an IP address.

This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.

QHostAddress is normally used with the QTcpSocketQTcpServer, and QUdpSocket to connect to a host or to set up a server.

A host address is set with setAddress(), and retrieved with toIPv4Address(), toIPv6Address(), or toString(). You can check the type with protocol().

Note: Please note that QHostAddress does not do DNS lookups. QHostInfo is needed for that.

The class also supports common predefined addresses: NullLocalHostLocalHostIPv6Broadcast, and Any.

See also QHostInfoQTcpSocketQTcpServer, and QUdpSocket.

  这个类提供了ip address,这个类提供了ip4和IP6地址的在平台与协议独立的方式。QHeostAddress是正常情况下与 QTcpSocket QTcpServer , and  QUdpSocket连接或者建立一个服务。

  

bool QHostAddress::isInSubnet ( const QHostAddress & subnet, int netmask ) const

Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask.

An IP is considered to belong to a subnet if it is contained between the lowest and the highest address in that subnet. In the case of IP version 4, the lowest address is the network address, while the highest address is the broadcast address.

The subnet argument does not have to be the actual network address (the lowest address in the subnet). It can be any valid IP belonging to that subnet. In particular, if it is equal to the IP address held by this object, this function will always return true (provided the netmask is a valid value).

This function was introduced in Qt 4.5.

 返回true假如ip在描写与网络前缀和子网的子网的子网,假如ip被考虑与属于子网假如它在最高和最低之间的子网,子网的没有必要是真实的网络地址、

     在讲一下QUdpSocket

bool QUdpSocket::bind ( const QHostAddress & addressquint16 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().

  绑定这个socket到这个地址和这个端口。在绑定的时候,这个信号开始发送当udp数据包在这个地址和端口上发过来的。如果绑定成功,这个函数返回,socket接近进入   BoundState。可以用 DefaultForPlatform   BindMode .的模式进行绑定,我来介绍有哪些模式,

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

 共享模式,他允许其他服务绑定相同的地址和端口。这是非常有用的当多线程的共同分担单一服务。不管这么样,任何的服务允许重新绑定,这是一个关于一定安全的课题。QUdpSocket::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.绑定地址和排他性的端口,以至于没有其他服务允许去重新绑定。通过这个属性,你被保证被连接,成功。你的监听服务唯一的没有允许去重新绑定的,尽管通过ReuseAddressHin。

      

QUdpSocket::ReuseAddressHint 0x4 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
这个模式,它提供了一个隐藏 QUdpSocke尽管这个地址和端口被其他绑定。

QUdpSocket::DefaultForPlatform 0x0 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.
  这是被默认的模式,在 on Windows,是共享的,On Unix and Mac OS X,是DontShareAddress + ReuseAddressHint

   

qint64 QUdpSocket::readDatagram ( char * dataqint64 maxSizeQHostAddress * address = 0, quint16 *port = 0 )

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.

 接受一个数据没有超过maxSize,存在data里面,发送者的地址和端口存在address和port




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值