Index: trunk/Cosy/tcpip/MTcpIpIO.cc
===================================================================
--- trunk/Cosy/tcpip/MTcpIpIO.cc	(revision 12597)
+++ trunk/Cosy/tcpip/MTcpIpIO.cc	(revision 12598)
@@ -62,7 +62,11 @@
 }
 
-MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout), MTcpIpO(addr, tx)
+MTcpIpCC::MTcpIpCC(Int_t rx, UInt_t timeout) : MTcpIpI(rx, timeout)
 {
     MTcpIpI::RunThread();
+}
+
+MTcpIpIO::MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout) : MTcpIpCC(rx, timeout), MTcpIpO(addr, tx)
+{
 }
 
@@ -277,5 +281,5 @@
 }
 
-bool MTcpIpIO::InterpreteStr(TString str)
+bool MTcpIpCC::InterpreteStr(TString str)
 {
     cout << "Rx: " << str << flush;
@@ -283,5 +287,5 @@
 }
 
-Bool_t MTcpIpIO::ReadSocket(TSocket &rx)
+Bool_t MTcpIpCC::ReadSocket(TSocket &rx)
 {
     TString str;
@@ -308,5 +312,5 @@
 
         // Data received (len==1)
-        if (c!='\n')
+        if (c!='\n' && c!=0)
         {
             str += c;
@@ -331,5 +335,10 @@
     }
 
+    fRxMutex.Lock();
+
     fConnectionEstablished = kTRUE;
+    fRxSocket = &sock;
+
+    fRxMutex.UnLock();
 
     MTimeout timeout(fTimeout);
@@ -409,6 +418,12 @@
         gLog << all << MTime(-1) << " Connection established to " << MTcpIpO::GetSocketAddress(*socket) << "..." << endl;
 
-        if (!WaitForData(*socket))
-            fConnectionEstablished = kFALSE;
+        WaitForData(*socket);
+
+        fRxMutex.Lock();
+
+        fRxSocket = 0;
+        fConnectionEstablished = kFALSE;
+
+        fRxMutex.UnLock();
 
 #ifdef DEBUG
@@ -455,4 +470,23 @@
 
     return 0;
+}
+
+bool MTcpIpFact::Send(const char *msg, int len)
+{
+    const Int_t mtx = fRxMutex.TryLock();
+    if (mtx==13)
+        gLog << warn << "MTcpIpO::Send - mutex is already locked by this thread." << endl;
+
+    // If Mutex cannot be locked, i.e. we are currently reopening
+    // the send socket we cannot wait, because we would block the
+    // executing threrad.
+    if (mtx)
+        return false;
+
+    const bool rc = fRxSocket ? MTcpIpO::SendFrame(*fRxSocket, msg, len) : false;
+
+    fRxMutex.UnLock();
+
+    return rc;
 }
 
Index: trunk/Cosy/tcpip/MTcpIpIO.h
===================================================================
--- trunk/Cosy/tcpip/MTcpIpIO.h	(revision 12597)
+++ trunk/Cosy/tcpip/MTcpIpIO.h	(revision 12598)
@@ -20,4 +20,8 @@
 class MTcpIpI : public MThread
 {
+protected:
+    TSocket *fRxSocket;
+    TMutex   fRxMutex;
+
 private:
     Int_t  fPortRx;     // Port on which to listen for connections
@@ -36,5 +40,5 @@
 
 public:
-    MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
+    MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fRxSocket(0), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
     ~MTcpIpI() { CancelThread(); }
 
@@ -65,6 +69,5 @@
 };
 
-// This class es espcially meant to receive and send ascii messages
-class MTcpIpIO : public MTcpIpI, public MTcpIpO
+class MTcpIpCC : public MTcpIpI
 {
 private:
@@ -72,7 +75,15 @@
 
 public:
-    MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000);
+    MTcpIpCC(Int_t rx, UInt_t timeout=5000);
 
     virtual bool InterpreteStr(TString str);
+};
+
+// This class es espcially meant to receive and send ascii messages
+class MTcpIpIO : public MTcpIpCC, public MTcpIpO
+{
+
+public:
+    MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000);
 };
 
@@ -91,3 +102,16 @@
 };
 
+class MTcpIpFact : public MTcpIpCC
+{
+private:
+
+public:
+    MTcpIpFact(const char *dumm1, Int_t dummy2, Int_t rx, UInt_t timeout) : MTcpIpCC(rx, timeout)
+    {
+    }
+
+    bool Send(const char *msg, int len);
+};
+
+
 #endif
