Skip to content

Commit

Permalink
Merge pull request #3 from Papierkorb/master
Browse files Browse the repository at this point in the history
C++ Example
  • Loading branch information
fuglu committed Oct 9, 2014
2 parents b07a0d7 + 9c9df88 commit b126033
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ We compiled a collection of server examples to get you started:
* [Python](https://github.com/sipgate/sipgate.io/tree/master/examples/python)
* [Ruby](https://github.com/sipgate/sipgate.io/tree/master/examples/ruby)
* [Scala](https://github.com/sipgate/sipgate.io/tree/master/examples/scala)
* [C++](https://github.com/sipgate/sipgate.io/tree/master/examples/c++)



Expand Down
35 changes: 35 additions & 0 deletions examples/c++/nuria/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* This is an example on how to create a fully functional HTTP server for use
* with the sipgate.io API based on the NuriaProject Framework.
* See: https://github.com/NuriaProject/Framework
*/

#include <QCoreApplication>
#include <nuria/httpclient.hpp>
#include <nuria/httpserver.hpp>
#include <nuria/httpnode.hpp>
#include <nuria/debug.hpp>

void mySlot (Nuria::HttpClient *client) {
Nuria::HttpPostBodyReader *reader = client->postBodyReader ();
if (!reader) {
client->killConnection (400);
return;
}

nLog() << "Incoming call" << reader->fieldValue ("from") << "->" << reader->fieldValue ("to");
}

int main (int argc, char *argv[]) {
QCoreApplication a (argc, argv);
Nuria::HttpServer server;

server.root ()->connectSlot ("index", mySlot);

if (!server.listen (QHostAddress::Any, 3000)) {
nError() << "Failed to listen on port 3000.";
return 1;
}

nLog() << "Listening on all interfaces on port 3000.";
return a.exec ();
}
12 changes: 12 additions & 0 deletions examples/c++/nuria/example.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Example project file for a sipgate.io HTTP server
TEMPLATE = app
TARGET = example
INCLUDEPATH += .

# Dependency to the NuriaProject Framework
# See https://github.com/NuriaProject/Framework
CONFIG += nuria
NURIA += core network

#
SOURCES += example.cpp

0 comments on commit b126033

Please sign in to comment.