Index: /trunk/BNC/bncapp.cpp
===================================================================
--- /trunk/BNC/bncapp.cpp	(revision 588)
+++ /trunk/BNC/bncapp.cpp	(revision 589)
@@ -91,4 +91,7 @@
   _ephStreamGlonass = 0;
 
+  _server  = 0;
+  _sockets = 0;
+
   _pgmName  = _bncVersion.leftJustified(20, ' ', true);
 #ifdef WIN32
@@ -108,4 +111,6 @@
   delete _ephStreamGPS;
   delete _ephFileGPS;
+  delete _server;
+  delete _sockets;
   if (_rinexVers == 2) {
     delete _ephStreamGlonass;
@@ -241,4 +246,14 @@
       }
       expandEnvVar(_ephPath);
+    }
+
+    // Socket Output
+    // -------------
+    _port = settings.value("outEphPort").toInt();
+    if (_port != 0) {
+      _server = new QTcpServer;
+      _server->listen(QHostAddress::Any, _port);
+      connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
+      _sockets = new QList<QTcpSocket*>;
     }
   }
@@ -456,11 +471,12 @@
     converttime(&cti, ep->GPSweek, ep->TOC);
 
-    if      (_rinexVers == 3) {
-      line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
-                   ep->satellite, cti.year, cti.month, cti.day, cti.hour,
-                   cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
-                   ep->clock_driftrate);
-    }
-    else if (_rinexVers == 2) {
+    QByteArray stream;
+
+    line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
+                 ep->satellite, cti.year, cti.month, cti.day, cti.hour,
+                 cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
+                 ep->clock_driftrate);
+    stream += line;
+    if (_rinexVers == 2) {
       line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
                    ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
@@ -472,16 +488,20 @@
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
                  ep->Crs, ep->Delta_n, ep->M0);
+    stream += line;
     *_ephStreamGPS << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
                  ep->e, ep->Cus, ep->sqrt_A);
+    stream += line;
     *_ephStreamGPS << line << endl;
 
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e",
                  (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
+    stream += line;
     *_ephStreamGPS << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->i0,
                  ep->Crc, ep->omega, ep->OMEGADOT);
+    stream += line;
     *_ephStreamGPS << line << endl;
 
@@ -494,4 +514,5 @@
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
                  (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
+    stream += line;
     *_ephStreamGPS << line << endl;
 
@@ -502,10 +523,24 @@
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", dd,
                  ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
+    stream += line;
     *_ephStreamGPS << line << endl;
 
     line.sprintf("   %19.12e%19.12e", ((double)ep->TOW), 0.0);
+    stream += line;
     *_ephStreamGPS << line << endl;
 
     _ephStreamGPS->flush();
+
+    // Output into the socket
+    // ----------------------
+    if (_sockets) {
+      QListIterator<QTcpSocket*> is(*_sockets);
+      while (is.hasNext()) {
+        QTcpSocket* sock = is.next();
+        if (sock->state() == QAbstractSocket::ConnectedState) {
+          sock->write(stream);
+        }
+      }
+    }
   }
 }
@@ -560,2 +595,9 @@
   }
 }
+
+// New Connection
+////////////////////////////////////////////////////////////////////////////
+void bncApp::slotNewConnection() {
+  _sockets->push_back( _server->nextPendingConnection() );
+}
+
Index: /trunk/BNC/bncapp.h
===================================================================
--- /trunk/BNC/bncapp.h	(revision 588)
+++ /trunk/BNC/bncapp.h	(revision 589)
@@ -43,4 +43,6 @@
     void slotNewGPSEph(gpsephemeris* gpseph);
     void slotNewGlonassEph(glonassephemeris* glonasseph);
+ private slots:
+   void slotNewConnection();
   private:
     void printEphHeader();
@@ -64,4 +66,7 @@
     QString           _userName;
     QString           _pgmName;
+    int                 _port;
+    QTcpServer*         _server;
+    QList<QTcpSocket*>* _sockets;
 };
 #endif
