Changeset 1518 in ntrip
- Timestamp:
- Jan 21, 2009, 10:40:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncnetqueryrtp.cpp
r1496 r1518 114 114 } 115 115 116 // Find a free port number117 // -----------------------118 int clientPortInt = 0;119 QTcpSocket* hlpSocket = new QTcpSocket();120 if ( proxyHost.isEmpty() ) {121 hlpSocket->connectToHost(urlLoc.host(), urlLoc.port());122 }123 else {124 hlpSocket->connectToHost(proxyHost, proxyPort);125 }126 if (hlpSocket->waitForConnected(timeOut)) {127 clientPortInt = hlpSocket->localPort();128 }129 delete hlpSocket;130 131 116 // Setup the RTSP Connection 132 117 // ------------------------- 133 if (clientPortInt) { 134 QByteArray clientPort = QString("%1").arg(clientPortInt).toAscii(); 135 delete _udpSocket; 136 _udpSocket = new QUdpSocket(); 137 _udpSocket->bind(clientPortInt); 138 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit())); 139 140 QByteArray reqStr; 141 reqStr = "SETUP " + urlLoc.toEncoded() + " RTSP/1.0\r\n" 142 + "CSeq: 1\r\n" 143 + "Ntrip-Version: Ntrip/2.0\r\n" 144 + "Ntrip-Component: Ntripclient\r\n" 145 + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n" 146 + "Transport: RTP/GNSS;unicast;client_port=" + clientPort + "\r\n" 147 + userAndPwd 148 + "\r\n"; 149 _socket->write(reqStr, reqStr.length()); 150 151 // Read Server Answer 1 152 // -------------------- 153 if (_socket->waitForBytesWritten(timeOut)) { 154 if (_socket->waitForReadyRead(timeOut)) { 155 QTextStream in(_socket); 156 QByteArray session; 157 QString line = in.readLine(); 158 while (!line.isEmpty()) { 159 if (line.indexOf("Session:") == 0) { 160 session = line.mid(9).toAscii(); 161 break; 162 } 163 line = in.readLine(); 118 delete _udpSocket; 119 _udpSocket = new QUdpSocket(); 120 _udpSocket->bind(0); 121 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit())); 122 QByteArray clientPort = QString("%1").arg(_udpSocket->localPort()).toAscii(); 123 124 QByteArray reqStr; 125 reqStr = "SETUP " + urlLoc.toEncoded() + " RTSP/1.0\r\n" 126 + "CSeq: 1\r\n" 127 + "Ntrip-Version: Ntrip/2.0\r\n" 128 + "Ntrip-Component: Ntripclient\r\n" 129 + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n" 130 + "Transport: RTP/GNSS;unicast;client_port=" + clientPort + "\r\n" 131 + userAndPwd 132 + "\r\n"; 133 _socket->write(reqStr, reqStr.length()); 134 135 // Read Server Answer 1 136 // -------------------- 137 if (_socket->waitForBytesWritten(timeOut)) { 138 if (_socket->waitForReadyRead(timeOut)) { 139 QTextStream in(_socket); 140 QByteArray session; 141 QString line = in.readLine(); 142 while (!line.isEmpty()) { 143 if (line.indexOf("Session:") == 0) { 144 session = line.mid(9).toAscii(); 145 break; 164 146 } 165 166 // Send Request 2 167 // -------------- 168 if (!session.isEmpty()) { 169 reqStr = "PLAY " + urlLoc.toEncoded() + " RTSP/1.0\r\n" 170 + "CSeq: 2\r\n" 171 + "Session: " + session + "\r\n" 172 + "\r\n"; 173 _socket->write(reqStr, reqStr.length()); 174 175 // Read Server Answer 2 176 // -------------------- 177 if (_socket->waitForBytesWritten(timeOut)) { 178 if (_socket->waitForReadyRead(timeOut)) { 179 QTextStream in(_socket); 147 line = in.readLine(); 148 } 149 150 // Send Request 2 151 // -------------- 152 if (!session.isEmpty()) { 153 reqStr = "PLAY " + urlLoc.toEncoded() + " RTSP/1.0\r\n" 154 + "CSeq: 2\r\n" 155 + "Session: " + session + "\r\n" 156 + "\r\n"; 157 _socket->write(reqStr, reqStr.length()); 158 159 // Read Server Answer 2 160 // -------------------- 161 if (_socket->waitForBytesWritten(timeOut)) { 162 if (_socket->waitForReadyRead(timeOut)) { 163 QTextStream in(_socket); 164 line = in.readLine(); 165 while (!line.isEmpty()) { 166 if (line.indexOf("200 OK") != -1) { 167 emit newMessage(urlLoc.host().toAscii() + 168 urlLoc.path().toAscii() + 169 ": UDP connection established", true); 170 return; 171 } 180 172 line = in.readLine(); 181 while (!line.isEmpty()) {182 if (line.indexOf("200 OK") != -1) {183 emit newMessage(urlLoc.host().toAscii() +184 urlLoc.path().toAscii() +185 ": UDP connection established", true);186 return;187 }188 line = in.readLine();189 }190 173 } 191 174 }
Note:
See TracChangeset
for help on using the changeset viewer.