]> git.zarvox.org Git - imoo.git/blobdiff - ribbon/ribbonserver.cpp
Length-coded framing for socket reads
[imoo.git] / ribbon / ribbonserver.cpp
index ec3d90264386a7a06b09d9d12be8ef3fb31e47b5..1c2ea15053abcb271deba81005d2bc96d8b5077f 100644 (file)
@@ -36,14 +36,24 @@ void RibbonServer::onNewConnection()
        }
        QObject::connect(rsock, SIGNAL(disconnected(RibbonSocket*)),
                        this, SLOT(onDisconnection(RibbonSocket*)));
+       QObject::connect(rsock, SIGNAL(messageReceived(RibbonSocket*,QByteArray)),
+                       this, SLOT(onMessageReceived(RibbonSocket*,QByteArray)));
 }
 
 void RibbonServer::onDisconnection(RibbonSocket* r)
 {
        sockets.removeOne(r);
        qDebug() << "Socket disconnected:" << r->s();
+       r->deleteLater();
        if (!server->isListening()) {
                server->listen(_addr, _port);
                qDebug() << "Server listening on" << _addr << ":" << _port;
        }
 }
+
+void RibbonServer::onMessageReceived(RibbonSocket* r, QByteArray buf)
+{
+       qDebug() << "server: got data from" << r->s()->peerAddress() << r->s()->peerPort();
+       qDebug() << "        message was:" << buf.constData();
+       // TODO: do something with the packet in buf.constData()
+}