Extending networking/socket programming functionality of a qml project
-
If you really need the noip address, then use QHostInfo.
Hardcoding means that you store some value within your code.
As for the settings, do you know what applications settings are ? Did you take a look at QSettings ?
@SGaist
I'm not sure why QSettings is needed, since as far as I know our intention is not storing something on the device the app is running on and then recalling that thing when the app reruns.
Yes, using QHostInfo it's possible to connect to noip or even my hostname there, but the problem is how to update the record at noip/my hostname so that the server's IP will be set there. :(As well as, I contacted noip and here's our talk:
-
Suppose I send both applications to two of my friends each in a different city. One of them runs the server app on their mobile device (using the Internet through Wifi connection) and the other guy runs the client app on their mobile device, again, connected to a Wifi.
What I, as the developer, can do is to modify the code for both apps to connect to my hostname "...ns.net". But the issue is, how is it possible for the server app to update a record there (on my hostname or so) to set its IP address in a way when the client app connects to my hostname, it can read the IP address of the server there and this way establish a connection, please?
What section of your website should I check for that service and use it for that goal, please? -
Here at No-IP we simply resolve a hostname or domain to an IP address; no data is ever passed through us nor do we issue any IP addresses. Our services does not connect your hostname to other networks unless you configure your hostname there. Best practices are 1 hostname per network location. You will not be able to set a single hostname for 2 or more locations. If you wish to connect to your friends server app, the hostname must be configured on their network in an update client to send out the current public IP address from that network. An update client can be either a router, a DDNS capable device, or the DUC that can be downloaded from your No-IP account.
Still I'm confused. :(
-
-
Can't anyone help me how to work the main issue out, please?
I believe the main issue is how to set the IP address of the server app on the noip website or my hostname to make it possible for the client app to get access to the server app and establish a connection. -
The main issue is that you currently do not understand properly how networking works.
As already written, your device automatically gets an IP address as soon as it is properly connected to a network be it WiFi, 4G/5G etc.
-
The main issue is that you currently do not understand properly how networking works.
As already written, your device automatically gets an IP address as soon as it is properly connected to a network be it WiFi, 4G/5G etc.
I understand this. Suppose the server app is running on a device with IP: 123.456.789
To give that address to the client app, you suggested noip. OK, I signed up and added a hostname too and posted my last talk with them above. Now the main issue is giving that address to the client app or as you say: updating a record on noip. How to do that? This is my problem. -
The client uses the host name that's all from its side.
You server needs to implement the client part that updates the noip record. Take a look at their client to implement that.
-
The client uses the host name that's all from its side.
You server needs to implement the client part that updates the noip record. Take a look at their client to implement that.
The client uses the host name that's all from its side.
The client connects to the hostname and gets its IP address. The IP of the hostname (I mean the one I added, "..dev.ddns.net") for example, is, 123.456.789, so the client now owns this address. Right?
You server needs to implement the client part that updates the noip record.
Does this mean that the server also needs to connect to the hostname above and gets that IP address!?
Take a look at their client to implement that.
Could you give me the address of that part, please?
-
No, the server has the address the client application is interested in. It does not get it from noip. noip is a DNS service that associates a hostname with an IP address, nothing more.
As for writing code, see their documentation about that matter.
-
No, the server has the address the client application is interested in. It does not get it from noip. noip is a DNS service that associates a hostname with an IP address, nothing more.
As for writing code, see their documentation about that matter.
@SGaist
Before writing the code, please let me understand the case completely.
The server has an IP address that the client is interested in (for establishing the connection). So how the client can know of that IP address?
The client can connect to hostname at noip and get the address of that hostname. But it's different from the server's IP! The server somehow should deliver its IP to the client for the connection. How is it done? -
The client just uses the hostname. That's all.
-
- So to sum it up: The client connects to my hostname which has been updated by the server to show its IP address and since this way the client can see the server's IP address it can connect to it. Right?
- If the above question is right, is this page the one I should study on how to make the server app update the hostname's record with its IP?
-
- Yes
- Looks like it yes.
-
So in my server app there should be a line of code as an HTTP request, like this example (of that page):
http://username:password@dynupdate.no-ip.com/nic/update?hostname=mytest.example.com&myip=192.0.2.25So if:
my username at noip is: coderdevqt@gmail.com
my password there is: passwordexample
and my hostname there is: coderdev.ddns.netthat HTTP request should be:
coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net
Right? -
Don't you think it would have been faster to just write and test the query ?
Also: https.
-
I'm not sure how to make an HTTP request using
QNetworkAccessManager
by a single string. I tired this but neither of theqInfo()
prints anything. The program also terminates at once! :|QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; manager->put(request,data); connect(manager, &QNetworkAccessManager::finished, [] { QNetworkReply* reply = nullptr; if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; reply->deleteLater(); });
-
I'm not sure how to make an HTTP request using
QNetworkAccessManager
by a single string. I tired this but neither of theqInfo()
prints anything. The program also terminates at once! :|QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; manager->put(request,data); connect(manager, &QNetworkAccessManager::finished, [] { QNetworkReply* reply = nullptr; if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; reply->deleteLater(); });
@qcoderpro said in Extending networking/socket programming functionality of a qml project:
connect(manager, &QNetworkAccessManager::finished, [] {
QNetworkReply* reply = nullptr;
if(reply->error()) -
I'm not sure how to make an HTTP request using
QNetworkAccessManager
by a single string. I tired this but neither of theqInfo()
prints anything. The program also terminates at once! :|QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; manager->put(request,data); connect(manager, &QNetworkAccessManager::finished, [] { QNetworkReply* reply = nullptr; if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; reply->deleteLater(); });
@qcoderpro
I would also suggest you do theconnect(manager, ...)
beforemanager->put()
not afterwards. -
@SGaist
What do you mean by copying part of the code I wrote above? I didn't get it. Do you mean those three lines of code are sufficient to make an Http request? Then how about the string!? :|@JonB
You mean this way?QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; connect(manager, &QNetworkAccessManager::finished, [] { QNetworkReply* reply = nullptr; if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; reply->deleteLater(); }); manager->put(request,data);
I'm confused! :(
Furthermore theput
function uploads the contents ofdata
to the destinationrequest
, while both my data and destination are packed into thatdata
! -
@SGaist
What do you mean by copying part of the code I wrote above? I didn't get it. Do you mean those three lines of code are sufficient to make an Http request? Then how about the string!? :|@JonB
You mean this way?QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; connect(manager, &QNetworkAccessManager::finished, [] { QNetworkReply* reply = nullptr; if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; reply->deleteLater(); }); manager->put(request,data);
I'm confused! :(
Furthermore theput
function uploads the contents ofdata
to the destinationrequest
, while both my data and destination are packed into thatdata
!@qcoderpro said in Extending networking/socket programming functionality of a qml project:
@JonB
You mean this way?Yes, I think it's preferable to attach the slot to
manager
's signal before you callmanager->put()
. Though @VRonin pointed out it doesn't actually matter in this case, but it's good style anyway. -
Since I've been summoned... how is this not a segfault?
QNetworkReply* reply = nullptr; if(reply->error())
What you should do is connect the
QNetworkReply
, not theQNetworkAccessManager
.// the initialisation of these 2 looks wrong but I'll ignore it for now QNetworkAccessManager* manager = new QNetworkAccessManager(this); const QNetworkRequest request; const QByteArray data {"https://coderdevqt@gmail.com:passwordexample@dynupdate.no-ip.com/nic/update?hostname=coderdev.ddns.net"}; QNetworkReply* reply = manager->put(request,data); connect(reply,&QNetworkReply::finished,this,[reply](){ if(reply->error()) qInfo() << "ERROR!: " + reply->errorString(); else qInfo() << "Reply got back with no error!"; }); connect(reply,&QNetworkReply::finished,reply,&QNetworkReply::deleteLater);