mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +08:00
Initial commit
This commit is contained in:
39
blacklib/samples/com_server/server.cpp
Normal file
39
blacklib/samples/com_server/server.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <blackmisc/debug.h>
|
||||
#include "server.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
Server::Server(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QHostAddress local = QHostAddress(QHostAddress::LocalHost);
|
||||
|
||||
server.Host(local, 6809);
|
||||
|
||||
connect(&server, SIGNAL(doMessageReceived(QString &, QByteArray&)), this, SLOT(onData(QString &, QByteArray&)));
|
||||
|
||||
CMessageSystem myMessageSystem;
|
||||
|
||||
bInfo << "Com Server running. \n";
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
{
|
||||
}
|
||||
|
||||
void Server::onData(QString &messageID, QByteArray &message)
|
||||
{
|
||||
BlackMisc::IMessage* test = BlackMisc::CMessageFactory::getInstance().create(messageID);
|
||||
QDataStream stream(&message, QIODevice::ReadOnly);
|
||||
|
||||
bAssert (test);
|
||||
*test << stream;
|
||||
|
||||
CMessageDispatcher::getInstance().append(test);
|
||||
CMessageDispatcher::getInstance().dispatch();
|
||||
|
||||
}
|
||||
|
||||
void TestMessageHandler::onTestMessage(const TestMessage *testmessage)
|
||||
{
|
||||
bDebug << "Message ID: " << testmessage->getID() << " with text: " << testmessage->getTestString();
|
||||
}
|
||||
Reference in New Issue
Block a user