Changeset 1411 in ntrip


Ignore:
Timestamp:
Dec 31, 2008, 12:51:14 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncnetqueryrtp.cpp

    r1410 r1411  
    55 * Class:      bncNetQueryRtp
    66 *
    7  * Purpose:    Blocking Network Requests (NTRIP Version 1)
     7 * Purpose:    Blocking Network Requests (NTRIP Version 2 with RTSP)
    88 *
    99 * Author:     L. Mervart
     
    6868  _socket = new QTcpSocket();
    6969
    70   // Default scheme and path
    71   // -----------------------
     70  // Default scheme
     71  // --------------
    7272  QUrl urlLoc(url);
    73   if (urlLoc.scheme().isEmpty()) {
    74     urlLoc.setScheme("http");
    75   }
    76   if (urlLoc.path().isEmpty()) {
    77     urlLoc.setPath("/");
    78   }
     73  urlLoc.setScheme("rtsp");
    7974
    8075  // Connect the Socket
     
    9085    _socket->connectToHost(proxyHost, proxyPort);
    9186  }
    92   if (!_socket->waitForConnected(timeOut)) {
    93     delete _socket;
    94     _socket = 0;
    95     _status = error;
    96     return;
     87
     88  // Send Request 1
     89  // --------------
     90  if (_socket->waitForConnected(timeOut)) {
     91    QString uName = QUrl::fromPercentEncoding(urlLoc.userName().toAscii());
     92    QString passW = QUrl::fromPercentEncoding(urlLoc.password().toAscii());
     93    QByteArray userAndPwd;
     94   
     95    if(!uName.isEmpty() || !passW.isEmpty()) {
     96      userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
     97      passW.toAscii()).toBase64() + "\r\n";
     98    }
     99   
     100    QByteArray clientPort = "7777"; // TODO: make it an option
     101   
     102    QByteArray reqStr;
     103    reqStr = "SETUP " + urlLoc.toEncoded() + " RTSP/1.0\r\n"
     104           + "Cseq: 1\r\n"
     105           + "Ntrip-Version: Ntrip/2.0\r\n"
     106           + "Ntrip-Component: Ntripclient\r\n"
     107           + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
     108           + "Transport: RTP/GNSS;unicast;client_port=" + clientPort + "\r\n"
     109           + userAndPwd
     110           + "\r\n";
     111    _socket->write(reqStr, reqStr.length());
     112   
     113    // Read Server Answer 1
     114    // --------------------
     115    if (_socket->waitForBytesWritten(timeOut)) {
     116      if (_socket->waitForReadyRead(timeOut)) {
     117        QTextStream in(_socket);
     118        QByteArray session;
     119        QString line = in.readLine();
     120        while (!line.isEmpty()) {
     121          cout << line.toAscii().data() << endl;;
     122          if (line.indexOf("Session:") == 0) {
     123            session = line.mid(9).toAscii();
     124          }
     125          line = in.readLine();
     126        }
     127
     128        // Send Request 2
     129        // --------------
     130        if (!session.isEmpty()) {
     131          reqStr = "PLAY " + urlLoc.toEncoded() + " RTSP/1.0\r\n"
     132                 + "Cseq: 2\r\n"
     133                 + "Session: " + session + "\r\n"
     134                 + "\r\n";
     135          _socket->write(reqStr, reqStr.length());
     136
     137          cout << reqStr.data();
     138
     139          // Read Server Answer 2
     140          // --------------------
     141          if (_socket->waitForBytesWritten(timeOut)) {
     142            if (_socket->waitForReadyRead(timeOut)) {
     143              QTextStream in(_socket);
     144              line = in.readLine();
     145              while (!line.isEmpty()) {
     146                cout << line.toAscii().data() << endl;
     147                if (line.indexOf("200 OK") != -1) {
     148                  cout << "Connection Established" << endl;
     149                  return;
     150                }
     151                line = in.readLine();
     152              }
     153            }
     154          }
     155        }
     156      }
     157    }
    97158  }
    98159
    99   // Send Request
    100   // ------------
    101   QString uName = QUrl::fromPercentEncoding(urlLoc.userName().toAscii());
    102   QString passW = QUrl::fromPercentEncoding(urlLoc.password().toAscii());
    103   QByteArray userAndPwd;
    104 
    105   if(!uName.isEmpty() || !passW.isEmpty()) {
    106     userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
    107     passW.toAscii()).toBase64() + "\r\n";
    108   }
    109 
    110   QByteArray reqStr;
    111   if ( proxyHost.isEmpty() ) {
    112     if (urlLoc.path().indexOf("/") != 0) urlLoc.setPath("/");
    113     reqStr = "GET " + urlLoc.path().toAscii() + " HTTP/1.0\r\n"
    114              + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
    115              + userAndPwd + "\r\n";
    116   } else {
    117     reqStr = "GET " + urlLoc.toEncoded() + " HTTP/1.0\r\n"
    118              + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
    119              + "Host: " + urlLoc.host().toAscii() + "\r\n"
    120              + userAndPwd + "\r\n";
    121   }
    122 
    123   // NMEA string to handle VRS stream
    124   // --------------------------------
    125   if (!gga.isEmpty()) {
    126     reqStr += gga + "\r\n";
    127   }
    128 
    129   _socket->write(reqStr, reqStr.length());
    130 
    131   if (!_socket->waitForBytesWritten(timeOut)) {
    132     delete _socket;
    133     _socket = 0;
    134     _status = error;
    135   }
     160  delete _socket;
     161  _socket = 0;
     162  _status = error;
    136163}
    137164
Note: See TracChangeset for help on using the changeset viewer.