QtNetwork active interface change detection - qt

I am aware this question is howto oriented, but I am getting desperate. Lets say some computer has more than one hardware network interface, eth0 and wlan0, the first one is onboard Ethernet port, the other one represents PCI WiFi card. What I would like to achieve is that the my Qt app while running, can detect if someone (for testing purposes, I myself) in operating system disconnects computer from LAN. Once app detects link failure, it tries to connect to same LAN via other available interface, wlan0 or vice versa.
I am reading Qt 5 Bearer management docs, but I simply do not get needed info. Now, should I open QNetworkSession with open() and connect to QNetworkSession::stateChanged(QNetworkSession::State state) or are there any other ways to do it in Qt fashion?

Related

How can the Android device programatically infer the IP address of the Linux device it's tethered to?

Hi! Asked this question on many forums and nobody could answer me so PLEASE help!
I have Android device connected to Linux device via USB tethering.
On Android device I have front-end(html, js, css) browser app and on Linux device I have back-end(node.js).
There is a socket connection between front-end and back-end with defined IP:PORT.
Androids gateway is Linux device. Linux device is connected to local network.
When Android device is connected to Linux device, Linux device initializes new network interface called usb0 with static IP address.
Sockets are based on that network IP that is same on every instance of front-end+back-end devices.
I have more than 5 instances of same front-end+back-end devices connected to local network.
Is there a way to somehow find the back-end device IP address without setting it static?
My problem starts when starting all devices at the same time. Sometimes Android device in instance 1 connects to Linux device from other instance and I want to prevent that by not connection to usb0 with Android but to eth0 DHCP of Linux device. I can never know which IP address will be on Linux device but front-end app needs a IP:PORT to connect.
PORT is defined so the string for connecting is {IP + ":3000"}
I know I can see all the IP addresses on network with arp or similar but I need to do that automatic in front-end app on app start up.
I want to find first device IP address that android device is connected to. That is always a front-ends pair Linux device.
Or if it is not possible to prevent Android device to be able to connect another instance with IP tables on Linux device.
P.S I know that Android is also Linux but someone who wants to answer will know what I'm talking about.
Here is a solution describing how to listen for tethering state changes:
First you need to be familiar with BroadcastReceiver. You can find a lot of tutorials describing in great detail how this works (try googling how to listen for connectivity changes in Android).
In order to get the Tethering state update, you need to use a hidden filter action of Android (see ConnectivityManager) and in your BroadcastReceiver class:
IntentFilter filter = new IntentFilter("android.net.conn.TETHER_STATE_CHANGED");
then register the filter to your BroadcastReceiver:
myApplicationContext.registerReceiver(this, filter);
In your onReceive(final Context context, final Intent intent) method, the Intent.extras information contains 3 arrays filled with the corresponding tethered network interface:
erroredArray / availableArray / activeArray
It's a little bit tricky but you can get the tethering status information.
In addition, you can do some reflexion on a hidden function of Android code:
Search for getTetherableIfaces() in the Connectivity Manager.
Here is a link: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/net/ConnectivityManager.java#L1604

How is chromecast initially discovered before even connecting to wifi?

How is chromecast initially discovered before even connecting to wifi? What is the underlying technology?
Is it done using multicast if so will a device get an ip before providing wifi password to send multicast
https://superuser.com/questions/626199/how-does-google-chromecast-connect-to-secured-wifi
Chromecast acts as an access point when first turned on. The software you install software on your andriod, windows or mac device will find it and connect to the chromecast's AP directly. Then the chromecast scans for access points allowing you to pick one and enter in your password. Once this is done, it will connect to that access point instead of acting as it's own access point.

Send files from Qt application on ethernet

I want to send files from Qt Application using Ethernet.As I click push Button the files must be transfered.
so my Question is:
Q: what are the configuration required because IP ,Net Mask is fixed in my device I am using :AM335x
:Linux OS
:Qt application
I am new to TCP/IP tell me how to proceed;
from Ethernet I am able to download Qt application executable file from PC to my device(AM335x) and it is running well .
But I want to send files from Am335x device to other device or PC.
Regards
Praveen
Basically what you want to be using is the Qt Network module. You can read about that here:
http://qt-project.org/doc/qt-5.0/qtnetwork/qtnetwork-programming.html
And find a class list here:
http://qt-project.org/doc/qt-5.0/qtnetwork/qtnetwork-module.html
Very briefly the two main classes you can use for TCP communication are QTcpServer and QTcpSocket. You can set up the server to listen for connections and it will return a QTcpSocket to do the actual communication. You can use the QTcpSocket for any outgoing communication.
If you don't want to use TCP, you can use datagrams (simpler, but ultimately less reliable). Here QUdpSocket is the main class to use, both for sending and receiving (you need to bind the socket to a port on your machine to receive).
It would be fairly easy to write a custom program to do simple file transfer based on these classes, however you can also look at higher level protocols designed to deal specifically with files.
For simple interaction with an FTP server at the other end of the connection you can use the QFtp class. An example of an FTP client application is here. Writing an FTP server in Qt would be rather more complicated, however you can look here: https://code.google.com/p/qt-ftp-server/.
All of this of this of course assumes that the Ethernet connection has been set up properly and that your computer has a valid IP address. Bear in mind that Ethernet is a link layer protocol and forms the raw basis for the higher level IP and TCP protocols. The idea of the higher level protocols is that they can used over a variety of link layers throughout the internet. It would be very unusual to write a program that interacts directly with a link layer protocol (unless of course you are writing a network stack for an OS).
On most networks configuration of IP addresses/netmasks etc is handled by a DHCP server running on one of the devices, most commonly on the router connecting everthing (if you have DHCP already running, then you probably don't have to worry). Without DHCP you can usually configure a static address and netmask on most devices. Choosing them is a fairly simple procedure. This page has a fairly good introduction to the concepts.
At first, you must be sure, that the target you want to send file to, is reachable. Use ping. If ping call is successful, then you can go further. Otherwise you should check your network settings to comply with your LAN.
You have then various ways to send files: FTP, HTTP, via netcat, using CIFS etc.

Which network topology does Windows 'hostednetwork' use? Is it equivalent to Ad-Hoc's topology?

I set up an Access Point using the following command:
netsh wlan set hostednetwork mode=allow ssid=DotA key=pass keyUsage=persistent
I am eager to know what topology (star, mesh etc.) does it use, so I may use it optimally as per my needs.
P.S.: I did post my question on SuperUser.com but got no response.
Hoping to be lucky here. :)
Microsoft says that
The wireless Hosted Network is a new WLAN feature supported on Windows 7 and on Windows Server 2008 R2 with the Wireless LAN Service installed. This feature implements two major functions:
The virtualization of a physical wireless adapter into more than one virtual wireless adapter sometimes referred to as Virtual Wi-Fi.
software-based wireless access point (AP) sometimes referred to as a SoftAP that uses a designated virtual wireless adapter.
and
With this feature, a Windows computer can use a single physical wireless adapter to connect as a client to a hardware access point (AP), while at the same time acting as a software AP allowing other wireless-capable devices to connect to it.
As it is on the AP mode (or managed mode) when you want to connect other wireless device to be connected to your laptop as a client (phone, laptop, tablet, etc.) so that it would be a star topology.
But when it connects to an Access Point like a WiFi router, then it will act as a client (or station adapter), then it would be a start topology again.
Mesh topology are commonly used on ad-hoc wlan mode.

Good commuication practices via Serial Port (RS232)

I want to know some general communication strategies, which should be followed for a communication via COM (serial) Port.
I can read/write at the port, also can list all the available ports on the machine. I'm using Qt C++ with QSerialDevice. For testing on a windows machine with no physical serial port, I'm using VPSE (virtual port)
Typical Flow (assumed):
List all the available serial ports of the computer.
Find out at which port my device (micro-controller) is connected - how to do it?
Device found.
Start a thread for reading from the port, another thread for writing it.
Safely close connection
Finding out at which port the device is connected sounds challenging to me. How to achieve it? I guess, I will send a HELLO message to each ports, if my device replies a specific per-defined reply message I can be sure my device is connected at that port. Can I?
Also I think, to seperate threads are necessary because at any time I may receive message from the Micro-controller device.
Thanks for helping :)

Resources