summaryrefslogtreecommitdiffstats
path: root/workspace/LogReceiver/logreceiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'workspace/LogReceiver/logreceiver.cpp')
-rw-r--r--workspace/LogReceiver/logreceiver.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp
new file mode 100644
index 0000000..9bca304
--- /dev/null
+++ b/workspace/LogReceiver/logreceiver.cpp
@@ -0,0 +1,70 @@
+ #include <QtGui>
+ #include <QtNetwork>
+
+ #include <stdlib.h>
+
+ #include "logreceiver.h"
+ #include <qlocalserver.h>
+ #include <qlocalsocket.h>
+
+
+LogReceiver::LogReceiver(QWidget *parent) :
+ QDialog(parent) {
+ ui.setupUi(this);
+
+ statusLabel = new QLabel;
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+ server = new QLocalServer(this);
+ if (!server->listen("/var/tmp/qt_c_socket_test")) {
+ QMessageBox::critical(this, tr("LogReceiver"), tr(
+ "Unable to start the server: %1.") .arg(server->errorString()));
+ close();
+ return;
+ }
+
+ statusLabel->setText(tr("The server is running.\n"
+ "Run the C Client example now."));
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Fortune Server"));
+}
+
+LogReceiver::~LogReceiver() {
+
+}
+
+
+ void LogReceiver::handleNewConnection()
+ {
+ qDebug() << "New Connection arrived";
+
+ clientSocket = server->nextPendingConnection();
+ connect(clientSocket, SIGNAL(disconnected()),
+ clientSocket, SLOT(deleteLater()));
+ connect(clientSocket, SIGNAL(readyRead()), this, SLOT(handleNewInput()));
+ }
+
+ void LogReceiver::handleNewInput() {
+
+ QByteArray data = clientSocket->readAll();
+
+ QString logMsg(data);
+ qDebug() << logMsg;
+
+ statusLabel->setText(logMsg);
+}
+