-
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
2,467 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @file tcpsocketclient.cpp | ||
* @date 17.07.2015 | ||
* @author Alexandre Poirot <alexandre.poirot@legrand.fr> | ||
* @brief tcpsocketclient.cpp | ||
*/ | ||
|
||
#include <jsonrpccpp/client.h> | ||
#include <jsonrpccpp/client/connectors/tcpsocketclient.h> | ||
#include <iostream> | ||
#include <cstdlib> | ||
|
||
using namespace jsonrpc; | ||
using namespace std; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
string host; | ||
unsigned int port; | ||
|
||
if(argc == 3) { | ||
host = string(argv[1]); | ||
port = atoi(argv[2]); | ||
} | ||
else { | ||
host = "127.0.0.1"; | ||
port = 6543; | ||
} | ||
|
||
|
||
cout << "Params are :" << endl; | ||
cout << "\t host: " << host << endl; | ||
cout << "\t port: " << port << endl; | ||
|
||
TcpSocketClient client(host, port); | ||
Client c(client); | ||
|
||
Json::Value params; | ||
params["name"] = "Peter"; | ||
|
||
try | ||
{ | ||
cout << c.CallMethod("sayHello", params) << endl; | ||
} | ||
catch (JsonRpcException& e) | ||
{ | ||
cerr << e.what() << endl; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @file unixdomainsocketserver.cpp | ||
* @date 11.05.2015 | ||
* @author Alexandre Poirot | ||
* @brief unixdomainsocketserver.cpp | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string> | ||
#include <iostream> | ||
#include <jsonrpccpp/server.h> | ||
#include <jsonrpccpp/server/connectors/tcpsocketserver.h> | ||
#include <cstdlib> | ||
|
||
|
||
using namespace jsonrpc; | ||
using namespace std; | ||
|
||
class SampleServer : public AbstractServer<SampleServer> | ||
{ | ||
public: | ||
SampleServer(TcpSocketServer &server) : | ||
AbstractServer<SampleServer>(server) | ||
{ | ||
this->bindAndAddMethod(Procedure("sayHello", PARAMS_BY_NAME, JSON_STRING, "name", JSON_STRING, NULL), &SampleServer::sayHello); | ||
this->bindAndAddNotification(Procedure("notifyServer", PARAMS_BY_NAME, NULL), &SampleServer::notifyServer); | ||
} | ||
|
||
//method | ||
void sayHello(const Json::Value& request, Json::Value& response) | ||
{ | ||
response = "Hello: " + request["name"].asString(); | ||
} | ||
|
||
//notification | ||
void notifyServer(const Json::Value& request) | ||
{ | ||
(void)request; | ||
cout << "server received some Notification" << endl; | ||
} | ||
}; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
try | ||
{ | ||
string ip; | ||
unsigned int port; | ||
|
||
if(argc == 3) | ||
{ | ||
ip = string(argv[1]); | ||
port = atoi(argv[2]); | ||
} | ||
else | ||
{ | ||
ip = "127.0.0.1"; | ||
port = 6543; | ||
} | ||
|
||
cout << "Params are :" << endl; | ||
cout << "\t ip: " << ip << endl; | ||
cout << "\t port: " << port << endl; | ||
|
||
TcpSocketServer server(ip, port); | ||
SampleServer serv(server); | ||
if (serv.StartListening()) | ||
{ | ||
cout << "Server started successfully" << endl; | ||
getchar(); | ||
serv.StopListening(); | ||
} | ||
else | ||
{ | ||
cout << "Error starting Server" << endl; | ||
} | ||
} | ||
catch (jsonrpc::JsonRpcException& e) | ||
{ | ||
cerr << e.what() << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @file unixdomainsocketclient.cpp | ||
* @date 11.05.2015 | ||
* @author Alexandre Poirot <alexandre.poirot@legrand.fr> | ||
* @brief unixdomainsocketclient.cpp | ||
*/ | ||
|
||
#include <jsonrpccpp/client.h> | ||
#include <jsonrpccpp/client/connectors/unixdomainsocketclient.h> | ||
#include <iostream> | ||
|
||
using namespace jsonrpc; | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
UnixDomainSocketClient client("/tmp/unixdomainsocketexample"); | ||
Client c(client); | ||
|
||
Json::Value params; | ||
params["name"] = "Peter"; | ||
|
||
try | ||
{ | ||
cout << c.CallMethod("sayHello", params) << endl; | ||
} | ||
catch (JsonRpcException& e) | ||
{ | ||
cerr << e.what() << endl; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.