--- /dev/null
+TEMPLATE = subdirs
+
+SUBDIRS = websocketclient \
+ websocketserver
--- /dev/null
+#include <QCoreApplication>
+#include "websocketclient.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+
+ WebSocketClient client;
+
+ Q_UNUSED(client);
+
+ return a.exec();
+}
--- /dev/null
+#include "websocketclient.h"
+#include <QDebug>
+
+WebSocketClient::WebSocketClient(QObject *parent) :
+ QObject(parent),
+ m_webSocket()
+{
+ connect(&m_webSocket, SIGNAL(connected()), this, SLOT(onConnected()));
+ m_webSocket.open(QUrl("ws://localhost:1234"));
+}
+
+void WebSocketClient::onConnected()
+{
+ qDebug() << "Websocket connected";
+ connect(&m_webSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString)));
+ m_webSocket.send("Hello, world!");
+}
+
+void WebSocketClient::onTextMessageReceived(QString message)
+{
+ qDebug() << "Message received:" << message;
+}
--- /dev/null
+#ifndef WEBSOCKETCLIENT_H
+#define WEBSOCKETCLIENT_H
+
+#include <QObject>
+#include "websocket.h"
+
+class WebSocketClient : public QObject
+{
+ Q_OBJECT
+public:
+ explicit WebSocketClient(QObject *parent = 0);
+
+Q_SIGNALS:
+
+public Q_SLOTS:
+
+private Q_SLOTS:
+ void onConnected();
+ void onTextMessageReceived(QString message);
+
+private:
+ WebSocket m_webSocket;
+};
+
+#endif // WEBSOCKETCLIENT_H
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-08-03T19:04:16
+#
+#-------------------------------------------------
+
+QT += core
+
+QT -= gui
+
+TARGET = websocketclient
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+include(../../source/websocket.pri)
+
+SOURCES += main.cpp \
+ websocketclient.cpp
+
+HEADERS += \
+ websocketclient.h
--- /dev/null
+#include "helloworldserver.h"
+#include "websocketserver.h"
+#include "websocket.h"
+#include <QDebug>
+
+HelloWorldServer::HelloWorldServer(quint16 port, QObject *parent) :
+ QObject(parent),
+ m_pWebSocketServer(0),
+ m_clients()
+{
+ m_pWebSocketServer = new WebSocketServer(this);
+ if (m_pWebSocketServer->listen(QHostAddress::Any, port))
+ {
+ qDebug() << "HelloWorld Server listening on port" << port;
+ connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
+ }
+}
+
+void HelloWorldServer::onNewConnection()
+{
+ qDebug() << "Client connected.";
+ WebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
+
+ connect(pSocket, SIGNAL(textFrameReceived(QString,bool)), this, SLOT(processMessage(QString, bool)));
+ //connect(pSocket, SIGNAL(binaryFrameReceived(QByteArray,bool)), this, SLOT(processBinaryMessage(QByteArray)));
+ connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+ //connect(pSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
+
+ m_clients << pSocket;
+}
+
+void HelloWorldServer::processMessage(QString message, bool isLastFrame)
+{
+ Q_UNUSED(isLastFrame);
+ WebSocket *pClient = qobject_cast<WebSocket *>(sender());
+ if (pClient != 0)
+ {
+ QString answer;
+ for (int i = 0; i < message.length(); ++i)
+ {
+ answer.push_front(message[i]);
+ }
+ pClient->send(answer);
+ }
+}
+
+void HelloWorldServer::socketDisconnected()
+{
+ WebSocket *pClient = qobject_cast<WebSocket *>(sender());
+ if (pClient != 0)
+ {
+ qDebug() << "Client disconnected";
+ m_clients.removeAll(pClient);
+ pClient->deleteLater();
+ }
+}
--- /dev/null
+#ifndef HELLOWORLDSERVER_H
+#define HELLOWORLDSERVER_H
+
+#include <QObject>
+#include <QList>
+
+class WebSocketServer;
+class WebSocket;
+
+class HelloWorldServer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit HelloWorldServer(quint16 port, QObject *parent = 0);
+
+Q_SIGNALS:
+
+private Q_SLOTS:
+ void onNewConnection();
+ void processMessage(QString message, bool isLastFrame);
+ void socketDisconnected();
+
+private:
+ WebSocketServer *m_pWebSocketServer;
+ QList<WebSocket *> m_clients;
+};
+
+#endif // HELLOWORLDSERVER_H
--- /dev/null
+#include <QCoreApplication>
+#include "helloworldserver.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+ HelloWorldServer server(1234);
+
+ Q_UNUSED(server);
+
+ return a.exec();
+}
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2013-08-03T19:54:35
+#
+#-------------------------------------------------
+
+QT += core
+
+QT -= gui
+
+TARGET = websocketserver
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+include(../../source/websocket.pri)
+
+SOURCES += main.cpp \
+ helloworldserver.cpp
+
+HEADERS += \
+ helloworldserver.h