diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h
index 73b1000a2ea45b82acb9f9b4dba040847d40fb33..53b252e6c99dca1e52e105c82cc53ade7566e88b 100644
--- a/src/plugins/debugger/debuggermanager.h
+++ b/src/plugins/debugger/debuggermanager.h
@@ -32,7 +32,6 @@
 
 #include <QtCore/QByteArray>
 #include <QtCore/QObject>
-#include <QtCore/QPoint>
 #include <QtCore/QStringList>
 #include <QtCore/QVariant>
 
@@ -42,19 +41,23 @@ class QAbstractItemModel;
 class QDockWidget;
 class QLabel;
 class QMainWindow;
-class QModelIndex;
-class QSplitter;
+class QPoint;
 class QTimer;
 class QWidget;
 QT_END_NAMESPACE
 
 namespace Core {
-    class IOptionsPage;
-}
+class IOptionsPage;
+} // namespace Core
 
 namespace Debugger {
 namespace Internal {
 
+typedef QLatin1Char _c;
+typedef QLatin1String __;
+inline QString _(const char *s) { return QString::fromLatin1(s); }
+inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
+
 class DebuggerOutputWindow;
 class DebuggerRunControl;
 class DebuggerPlugin;
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index a06aa38e3d86b1b24ca8065f0a62d71cf7b8c284..41a2f88ff7f0f611e1be25b961536d3ff5c91153 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -483,7 +483,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
     connect(m_attachCoreAction, SIGNAL(triggered()), this, SLOT(attachCore()));
 
     m_attachTcfAction = new QAction(this);
-    m_attachTcfAction->setText(tr("Attach to Running TCF Agent..."));
+    m_attachTcfAction->setText(tr("Attach to Running Tcf Agent..."));
     m_attachTcfAction->setToolTip(tr("This attaches to a running "
         "'Target Communication Framework' agent."));
     connect(m_attachTcfAction, SIGNAL(triggered()),
diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp
index 583b9aa5c100f7d0485db4ebf84ec67c649344d8..531b74b6a71e2f3f765776354234f39331478d40 100644
--- a/src/plugins/debugger/gdbengine.cpp
+++ b/src/plugins/debugger/gdbengine.cpp
@@ -91,18 +91,8 @@ Q_DECLARE_METATYPE(Debugger::Internal::GdbMi);
 
 #define STRINGIFY_INTERNAL(x) #x
 #define STRINGIFY(x) STRINGIFY_INTERNAL(x)
-
 #define CB(callback) &GdbEngine::callback, STRINGIFY(callback)
 
-typedef QLatin1Char _c;
-typedef QLatin1String __;
-static inline QString _(const char *s) { return QString::fromLatin1(s); }
-
-static inline QString _(const QByteArray &ba)
-{
-    return QString::fromLatin1(ba.data(), ba.size());
-}
-
 static int &currentToken()
 {
     static int token = 0;
diff --git a/src/plugins/debugger/tcfengine.cpp b/src/plugins/debugger/tcfengine.cpp
index 6d31ed7e55734e36122e8dd9b78563ece04e2a64..e22c3596732d3f2efd8cfc2b88cba4f0e2f10df3 100644
--- a/src/plugins/debugger/tcfengine.cpp
+++ b/src/plugins/debugger/tcfengine.cpp
@@ -51,14 +51,18 @@
 
 #include <QtGui/QAction>
 #include <QtGui/QApplication>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMessageBox>
 #include <QtGui/QToolTip>
 
+#include <QtNetwork/QTcpSocket>
+
 
 using namespace Debugger;
 using namespace Debugger::Internal;
 using namespace Debugger::Constants;
 
-//#define DEBUG_TCF 1
+#define DEBUG_TCF 1
 #if DEBUG_TCF
 #   define SDEBUG(s) qDebug() << s
 #else
@@ -66,6 +70,10 @@ using namespace Debugger::Constants;
 #endif
 # define XSDEBUG(s) qDebug() << s
 
+#define STRINGIFY_INTERNAL(x) #x
+#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
+#define CB(callback) &TcfEngine::callback, STRINGIFY(callback)
+
 ///////////////////////////////////////////////////////////////////////
 //
 // TcfEngine
@@ -76,12 +84,66 @@ TcfEngine::TcfEngine(DebuggerManager *parent)
 {
     q = parent;
     qq = parent->engineInterface();
+    m_socket = new QTcpSocket(this);
+    connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected()));
+    connect(m_socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
+        this, SLOT(socketError(QAbstractSocket::SocketError)));
+
+    //void aboutToClose ()
+    //void bytesWritten ( qint64 bytes )
+    //void readChannelFinished ()
+    connect(m_socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
+
+    //connect(m_socket, SIGNAL(hostFound())
+    //connect(m_socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator *)))
+    //connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+    //    thism SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+
+    connect(this, SIGNAL(tcfOutputAvailable(QString,QString)),
+        q, SLOT(showDebuggerOutput(QString,QString)),
+        Qt::QueuedConnection);
+    connect(this, SIGNAL(tcfInputAvailable(QString,QString)),
+        q, SLOT(showDebuggerInput(QString,QString)),
+        Qt::QueuedConnection);
+    connect(this, SIGNAL(applicationOutputAvailable(QString)),
+        q, SLOT(showApplicationOutput(QString)),
+        Qt::QueuedConnection);
 }
 
 TcfEngine::~TcfEngine()
 {
 }
 
+void TcfEngine::socketReadyRead()
+{
+    //XSDEBUG("TcfEngine::socketReadyRead()");
+    m_inbuffer.append(m_socket->readAll());
+    //handleResponse(QByteArray::fromRawData(m_inbuffer.constData() + start, end - start));
+    handleResponse(m_inbuffer);
+    m_inbuffer.clear();
+}
+
+void TcfEngine::socketConnected()
+{
+    q->showStatusMessage("Socket connected.");
+    m_socket->waitForConnected(2000);
+    //sendCommand("Locator", "redirect", "ID");
+}
+
+void TcfEngine::socketDisconnected()
+{
+    XSDEBUG("FIXME:  TcfEngine::socketDisconnected()");
+}
+
+void TcfEngine::socketError(QAbstractSocket::SocketError)
+{
+    QString msg = tr("Socket error: %1").arg(m_socket->errorString());
+    QMessageBox::critical(q->mainWindow(), tr("Error"), msg);
+    q->showStatusMessage(msg);
+    qq->notifyInferiorExited();
+}
+
 void TcfEngine::executeDebuggerCommand(const QString &command)
 {
     Q_UNUSED(command);
@@ -102,7 +164,11 @@ void TcfEngine::exitDebugger()
 bool TcfEngine::startDebugger()
 {
     qq->notifyInferiorRunningRequested();
-    QTimer::singleShot(0, this, SLOT(runInferior()));
+    int pos = q->m_remoteChannel.indexOf(':');
+    QString host = q->m_remoteChannel.left(pos);
+    quint16 port = q->m_remoteChannel.mid(pos + 1).toInt();
+    //QTimer::singleShot(0, this, SLOT(runInferior()));
+    m_socket->connectToHost(host, port);
     return true;
 }
 
@@ -202,6 +268,88 @@ QList<Symbol> TcfEngine::moduleSymbols(const QString & /*moduleName*/)
 }
 
 
+void TcfEngine::handleResponse(const QByteArray &buf)
+{
+    static QTime lastTime;
+
+    //emit tcfOutputAvailable(_("            "), currentTime());
+    TcfResponse response;
+    QList<QByteArray> parts = buf.split('\0');
+    int n = parts.size();
+    if (n >= 1)
+        response.tag = parts.at(0);
+    if (n >= 2)
+        response.service = parts.at(1);
+    if (n >= 3)
+        response.cmd = parts.at(2);
+    if (n >= 4)
+        response.data = parts.at(3);
+    if (response.cmd != "peerHeartBeat")
+        emit tcfOutputAvailable(_("\ntcf:"), quoteUnprintableLatin1(buf));
+    //emit tcfOutputAvailable(_("\ntcf:"), response.toString());
+    qDebug() << response.toString();
+
+    if (response.service == "Locator" && response.cmd == "Hello") {
+        postCommand('C', CB(handleRunControlSuspend),
+            "RunControl", "suspend", "\"Thread1\"");
+        //postCommand('F', "0", "", "");
+        //postCommand('E', "Locator", "Hello", "");
+        //postCommand('C', "Locator", "sync", "");
+        //postCommand("Locator", "redirect", "ID");
+        return;
+    }
+
+    TcfCommand tcf = m_cookieForToken[1];
+    if (tcf.callback)
+        (this->*(tcf.callback))(response, tcf.cookie);
+}
+
+void TcfEngine::postCommand(char tag,
+    TcfCommandCallback callback,
+    const char *callbackName,
+    const QByteArray &service,
+    const QByteArray &cmd,
+    const QByteArray &args)
+{
+    static int token;
+    ++token;
+    
+    const char delim = 0;
+    const char marker_eom = -1;
+    const char marker_eos = -2;
+    const char marker_null = -3;
+
+    QByteArray ba;
+    ba.append(tag);
+    ba.append(delim);
+    ba.append(QString::number(token).toLatin1());
+    ba.append(delim);
+    ba.append(service);
+    ba.append(delim);
+    ba.append(cmd);
+    ba.append(delim);
+    ba.append(args);
+    ba.append(delim);
+    ba.append(3);
+    ba.append(1);
+
+    TcfCommand tcf;
+    tcf.command = ba;
+    tcf.callback = callback;
+
+    m_cookieForToken[token] = tcf;
+
+    emit tcfInputAvailable("send", quoteUnprintableLatin1(ba));
+    int result = m_socket->write(tcf.command);
+    m_socket->flush();
+    emit tcfInputAvailable("send", QString::number(result));
+}
+
+void TcfEngine::handleRunControlSuspend(const TcfResponse &response, const QVariant &)
+{
+    qDebug() << "HANDLE RESULT";
+}
+
 //////////////////////////////////////////////////////////////////////
 //
 // Tooltip specific stuff
diff --git a/src/plugins/debugger/tcfengine.h b/src/plugins/debugger/tcfengine.h
index a8b74a4bbfd83eba5c7ca81481e36cab4e0a514c..6651af8e42d2314844ea438be0f66b210902fae2 100644
--- a/src/plugins/debugger/tcfengine.h
+++ b/src/plugins/debugger/tcfengine.h
@@ -39,16 +39,14 @@
 #include <QtCore/QSet>
 #include <QtCore/QVariant>
 
+#include <QtNetwork/QAbstractSocket>
+
 QT_BEGIN_NAMESPACE
-class QAction;
-class QAbstractItemModel;
-class QSplitter;
-class QToolBar;
-class QScriptEngine;
-class QScriptValue;
+class QTcpSocket;
 QT_END_NAMESPACE
 
 #include "idebuggerengine.h"
+#include "debuggermanager.h"
 
 namespace Debugger {
 namespace Internal {
@@ -58,6 +56,27 @@ class IDebuggerManagerAccessForEngines;
 class ScriptAgent;
 class WatchData;
 
+class TcfResponse
+{
+public:
+    enum ResponseType
+    {
+        HelloResponse,
+        HeartBeatResponse
+    };
+
+    QString toString() const
+    {
+        return _("TAG: " + tag + "  SERVICE: " + service
+            + "  CMD: " + cmd + "  DATA: " + data);
+    }
+
+    QByteArray tag;
+    QByteArray service;
+    QByteArray cmd;
+    QByteArray data;
+};
+
 class TcfEngine : public IDebuggerEngine
 {
     Q_OBJECT
@@ -66,6 +85,11 @@ public:
     explicit TcfEngine(DebuggerManager *parent);
     ~TcfEngine();
 
+signals:
+    void tcfInputAvailable(const QString &prefix, const QString &msg);
+    void tcfOutputAvailable(const QString &prefix, const QString &msg);
+    void applicationOutputAvailable(const QString &output);
+
 private:
     // IDebuggerEngine implementation
     void stepExec();
@@ -110,9 +134,41 @@ private:
     void updateLocals();
     void updateSubItem(const WatchData &data0);
 
+    Q_SLOT void socketConnected();
+    Q_SLOT void socketDisconnected();
+    Q_SLOT void socketError(QAbstractSocket::SocketError);
+    Q_SLOT void socketReadyRead();
+
+    void handleResponse(const QByteArray &ba);
+    void handleRunControlSuspend(const TcfResponse &response, const QVariant &);
+
 private:
+    typedef void (TcfEngine::*TcfCommandCallback)
+        (const TcfResponse &record, const QVariant &cookie);
+
+    struct TcfCommand
+    {
+        TcfCommand() : flags(0), callback(0), callbackName(0) {}
+
+        int flags;
+        TcfCommandCallback callback;
+        const char *callbackName;
+        QByteArray command;
+        QVariant cookie;
+    };
+
+    void postCommand(char tag,
+        TcfCommandCallback callback,
+        const char *callbackName,
+        const QByteArray &service,
+        const QByteArray &cmd, const QByteArray &args);
+
+    QHash<int, TcfCommand> m_cookieForToken;
+
     DebuggerManager *q;
     IDebuggerManagerAccessForEngines *qq;
+    QTcpSocket *m_socket;
+    QByteArray m_inbuffer;
 };
 
 } // namespace Internal
diff --git a/src/plugins/debugger/watchutils.cpp b/src/plugins/debugger/watchutils.cpp
index 812442a323896035a84c03c235772bf6143e3680..a665bd774eef650b3ebc311533fc3def9a250ae4 100644
--- a/src/plugins/debugger/watchutils.cpp
+++ b/src/plugins/debugger/watchutils.cpp
@@ -313,7 +313,7 @@ QString sizeofTypeExpression(const QString &type)
 
 // Utilities to decode string data returned by the dumper helpers.
 
-static QString quoteUnprintableLatin1(const QByteArray &ba)
+QString quoteUnprintableLatin1(const QByteArray &ba)
 {
     QString res;
     char buf[10];
diff --git a/src/plugins/debugger/watchutils.h b/src/plugins/debugger/watchutils.h
index af0a20c3b7c66299f5eba4112996b6fa883517c7..e9d8ab79105ec30d891260eb0f4aaf3deaa14d56 100644
--- a/src/plugins/debugger/watchutils.h
+++ b/src/plugins/debugger/watchutils.h
@@ -65,6 +65,7 @@ bool extractTemplate(const QString &type, QString *tmplate, QString *inner);
 QString extractTypeFromPTypeOutput(const QString &str);
 bool isIntOrFloatType(const QString &type);
 QString sizeofTypeExpression(const QString &type);
+QString quoteUnprintableLatin1(const QByteArray &ba);
 
 // Decode string data as returned by the dumper helpers.
 QString decodeData(const QByteArray &baIn, int encoding);