• 动态IP获取


    自己用ARM9实现了网络摄像头

    但是家里拨号到ip老是变,导致公网外部老是访问不了。

    所以想了一下,本来想用邮箱做IP记录

     现在直接用php实现

    <?php
    if(isset($_GET["chk"]))
    {
      $file_pointer = fopen("ip","w");
      fwrite($file_pointer,$_SERVER["REMOTE_ADDR"]);
      fclose($file_pointer);

      echo $_SERVER["REMOTE_ADDR"];
    }else{
      echo file_get_contents("ip");
    }

    ?> 

    嵌入式里面每隔5分钟访问ip.php?chk=c

    QT嵌入式代码

    qsetip.h

    #ifndef QSETIP_H

    #define QSETIP_H
    #include <QUrl>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QDebug>
    class QSetIp : public QObject
    {
        Q_OBJECT
    private:
        QUrl url;
        QNetworkAccessManager* qnam;
        QNetworkReply *reply;
        int httpGetId;
        bool httpRequestAborted;
    public:
        explicit QSetIp(QObject *parent = 0);
        void startRequest(QUrl url);
    signals:
        void httpFinish(QString result);
    public slots:
        void httpFinished();
    };
    #endif // QSETIP_H
    
    
    
    

    qsetip.cpp

    #include "qsetip.h"

    QSetIp::QSetIp(QObject *parent) :
            QObject(parent)
    {
    }
    void QSetIp::startRequest(QUrl url)
    {
        qnam = new QNetworkAccessManager(this);
        reply = qnam->get(QNetworkRequest(url));
        connect(reply, SIGNAL(finished()), this, SLOT(httpFinished()));
    }
    void QSetIp::httpFinished()
    {
        if (httpRequestAborted) {
            QString html = reply->readAll();
            httpFinish(html);
            qDebug()<< html;
            reply = 0;
        }
    }
    
    

    在程序启动 加入

    QTimer *timer = new QTimer(this);

    connect(timer, SIGNAL(timeout()), this, SLOT(runGet()));
    timer->start(5000);

    建立slot

    void MainWindow::runGet()

    {
        setIpClass = new QSetIp(this);
        setIpClass->startRequest(QUrl("http://www.xxxxxx.com/ip.php?chk=1"));
    }


     

  • 相关阅读:
    探讨.net Socket支持在线连接数量
    Net Configuration Agent
    Http压力测试工具HttpTest4Net
    TCP连接有效性检测方法
    SocketAsyncEventArgs使用解说
    可靠、高吞吐架构基础改造
    PerformanceCounter蛋痛的设计
    谱聚类(spectral clustering)原理总结
    用scikit-learn学习DBSCAN聚类
    DBSCAN密度聚类算法
  • 原文地址:https://www.cnblogs.com/kenter/p/1827966.html
Copyright © 2020-2023  润新知