[Qt] Qtcpsocket get the IP address small bug

Source: Internet
Author: User



When I tested the code yesterday, I found a very strange problem, in the lab, I run the server on a server, with my classmate's computer running the client is completely normal. But when I test the code at night in the dorm, one computer runs the client and the server, and the other runs the client, but it's always an exception, the same code, why the results are different?

The client is a multi-to-many audio and video call, the server side assists the connection. The experimental results of the dormitory are two cases ① two clients die as long as the connection is ② one client receives its own audio and video, while the other client always shows that the audio and video stream is occupied. In particular, the second phenomenon is very inconsistent with common sense! Two clients are equivalent, how to experiment phenomenon will appear different?!

Later, I looked through the stream of SDP file records, found that some of the IP address is 127.0.0.1, and some appear:: 1 such an IP address. In retrospect, I originally ran the client on the machine that had served as the server, in order to save trouble, sometimes the IP was set to 127.0.0.1, sometimes simply set as localhost.

When the host to which the client is connecting is localhost, the address string in the client TCP link pointer obtained by the server side Qtcpsocket *->peeraddress () should be ":: 1".

When the host is "127.0.0.1", the server side gets the address string of the client TCP link pointer qtcpsocket *->peeraddress () Unexpectedly is also "127.0.0.1", these two cases is not the real IP address at all.

Figures:




[Qt] Qtcpsocket get the IP address small bug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.