summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlocalsocket/example
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 09:34:13 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 09:34:13 (GMT)
commit67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch)
tree1dbf50b3dff8d5ca7e9344733968c72704eb15ff /tests/auto/qlocalsocket/example
downloadQt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip
Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz
Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2
Long live Qt!
Diffstat (limited to 'tests/auto/qlocalsocket/example')
-rw-r--r--tests/auto/qlocalsocket/example/client/client.pro16
-rw-r--r--tests/auto/qlocalsocket/example/client/main.cpp84
-rw-r--r--tests/auto/qlocalsocket/example/example.pro3
-rw-r--r--tests/auto/qlocalsocket/example/server/main.cpp97
-rw-r--r--tests/auto/qlocalsocket/example/server/server.pro19
5 files changed, 219 insertions, 0 deletions
diff --git a/tests/auto/qlocalsocket/example/client/client.pro b/tests/auto/qlocalsocket/example/client/client.pro
new file mode 100644
index 0000000..eb7e6e6
--- /dev/null
+++ b/tests/auto/qlocalsocket/example/client/client.pro
@@ -0,0 +1,16 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Wed Jun 6 17:07:12 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG += console
+include(../../src/src.pri)
+# Input
+QT = core network
+
+SOURCES += main.cpp
+
+
diff --git a/tests/auto/qlocalsocket/example/client/main.cpp b/tests/auto/qlocalsocket/example/client/main.cpp
new file mode 100644
index 0000000..76050af
--- /dev/null
+++ b/tests/auto/qlocalsocket/example/client/main.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <string.h>
+#include <qstring.h>
+#include <qdebug.h>
+
+#include "qlocalsocket.h"
+
+#define SOCK_PATH "echo_socket"
+
+int main(void)
+{
+ QLocalSocket socket;
+ socket.connectToServer(SOCK_PATH);
+ socket.open(QIODevice::ReadWrite);
+
+ printf("Connected.\n");
+ char str[100];
+ while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
+ if (socket.write(str, strlen(str)) == -1) {
+ perror("send");
+ return EXIT_FAILURE;
+ }
+
+ int t;
+ if ((t = socket.read(str, 100)) > 0) {
+ str[t] = '\0';
+ printf("echo> %s", str);
+ } else {
+ if (t < 0)
+ perror("recv");
+ else
+ printf("Server closed connection.\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/tests/auto/qlocalsocket/example/example.pro b/tests/auto/qlocalsocket/example/example.pro
new file mode 100644
index 0000000..8c678cd
--- /dev/null
+++ b/tests/auto/qlocalsocket/example/example.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = client server
+
diff --git a/tests/auto/qlocalsocket/example/server/main.cpp b/tests/auto/qlocalsocket/example/server/main.cpp
new file mode 100644
index 0000000..bb2fc77
--- /dev/null
+++ b/tests/auto/qlocalsocket/example/server/main.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "qlocalserver.h"
+#include "qlocalsocket.h"
+
+#include <qcoreapplication.h>
+#include <qdebug.h>
+
+class EchoServer : public QLocalServer
+{
+public:
+ void incomingConnection(int socketDescriptor) {
+ QLocalServer::incomingConnection(socketDescriptor);
+ QLocalSocket *socket = nextPendingConnection();
+ socket->open(QIODevice::ReadWrite);
+
+ qDebug() << "server connection";
+
+ do {
+ const int Timeout = 5 * 1000;
+ while (!socket->canReadLine()) {
+ if (!socket->waitForReadyRead(Timeout)) {
+ return;
+ }
+ }
+ char str[100];
+ int n = socket->readLine(str, 100);
+ if (n < 0) {
+ perror("recv");
+ break;
+ }
+ if (n == 0)
+ break;
+ qDebug() << "Read" << str;
+ if ("exit" == str)
+ qApp->quit();
+
+ if (socket->write(str, 100) < 0) {
+ perror("send");
+ break;
+ }
+ } while (true);
+ }
+};
+
+#define SOCK_PATH "echo_socket"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication application(argc, argv);
+
+ EchoServer echoServer;
+ echoServer.listen(SOCK_PATH);
+
+ return application.exec();
+}
+
diff --git a/tests/auto/qlocalsocket/example/server/server.pro b/tests/auto/qlocalsocket/example/server/server.pro
new file mode 100644
index 0000000..438462d
--- /dev/null
+++ b/tests/auto/qlocalsocket/example/server/server.pro
@@ -0,0 +1,19 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Wed Jun 6 15:16:48 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+CONFIG += console
+
+QT = core network
+
+include(../../src/src.pri)
+
+# Input
+SOURCES += main.cpp
+
+