mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
.upptst
git-svn-id: svn://ultimatepp.org/upp/trunk@5069 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
15ef7e6260
commit
fdcf80446f
6 changed files with 141 additions and 0 deletions
40
upptst/XmlRpcClient/XmlRpcClient.cpp
Normal file
40
upptst/XmlRpcClient/XmlRpcClient.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include <Core/Core.h>
|
||||
#include <Core/XMLRpc/XMLRpc.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
namespace Upp {
|
||||
extern bool HttpRequest_Trace__;
|
||||
}
|
||||
|
||||
void Compute( double a, Upp::String arithmeticOperator, double b );
|
||||
|
||||
int main() {
|
||||
Time serverTime;
|
||||
SetDateFormat( "%4d-%02d-%02d" );
|
||||
XmlRpcRequest call( "127.0.0.1:1234" );
|
||||
if( call("GetServerTime") >> serverTime ) {
|
||||
LOG( "Server Time = " << serverTime );
|
||||
}
|
||||
else {
|
||||
LOG( Upp::Format("Error: %s", call.GetError()) );
|
||||
}
|
||||
|
||||
Compute( 12, "+", 12 );
|
||||
Compute( 12, "*", 12 );
|
||||
Compute( 12, "+56", 12 );
|
||||
Compute( 12, "/", 0 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Compute( double a, Upp::String arithmeticOperator, double b ) {
|
||||
double result = 0;
|
||||
XmlRpcRequest call( "127.0.0.1:1234" );
|
||||
if( call("Compute", a, arithmeticOperator, b) >> result ) {
|
||||
LOG( Upp::Format("%f %s %f = %f", a, arithmeticOperator, b, result) );
|
||||
}
|
||||
else {
|
||||
LOG( Upp::Format("Error: %s", call.GetError()) );
|
||||
}
|
||||
}
|
||||
10
upptst/XmlRpcClient/XmlRpcClient.upp
Normal file
10
upptst/XmlRpcClient/XmlRpcClient.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core,
|
||||
Core\XmlRpc;
|
||||
|
||||
file
|
||||
XmlRpcClient.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
5
upptst/XmlRpcClient/init
Normal file
5
upptst/XmlRpcClient/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _XmlRpcClient_icpp_init_stub
|
||||
#define _XmlRpcClient_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "Core\XmlRpc/init"
|
||||
#endif
|
||||
71
upptst/XmlRpcServer/XmlRpcServer.cpp
Normal file
71
upptst/XmlRpcServer/XmlRpcServer.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#include <conio.h>
|
||||
#include <Core/Core.h>
|
||||
#include <Core/XMLRpc/XMLRpc.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
XMLRPC_METHOD( Compute ) {
|
||||
double a, b;
|
||||
Upp::String arithmeticOperator;
|
||||
rpc >> a >> arithmeticOperator >> b;
|
||||
LOG( Upp::Format("Request: %nf %s %nf", a, arithmeticOperator, b) );
|
||||
|
||||
if( arithmeticOperator.GetCount() == 1 ) {
|
||||
switch( *arithmeticOperator ) {
|
||||
case '+': {
|
||||
rpc << a + b;
|
||||
break;
|
||||
}
|
||||
case '-': {
|
||||
rpc << a - b;
|
||||
break;
|
||||
}
|
||||
case '/': {
|
||||
if( b == 0 ) {
|
||||
rpc << Upp::ErrorValue("division by zero");
|
||||
}
|
||||
else {
|
||||
rpc << a / b;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '*': {
|
||||
rpc << a * b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
rpc << Upp::ErrorValue("unknown operator");
|
||||
}
|
||||
}
|
||||
|
||||
XMLRPC_METHOD( GetServerTime ) {
|
||||
LOG( "Request: GetServerTime" );
|
||||
rpc << Upp::GetSysTime();
|
||||
}
|
||||
|
||||
int main() {
|
||||
TcpSocket rpc;
|
||||
int port = 1234;
|
||||
|
||||
if( !rpc.Listen(port,5) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while( true ) {
|
||||
if( _kbhit() ) {
|
||||
if( _getch() == 27 ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TcpSocket http;
|
||||
http.Timeout(1000);
|
||||
if( http.Accept(rpc) ) {
|
||||
XmlRpcPerform(http,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
upptst/XmlRpcServer/XmlRpcServer.upp
Normal file
10
upptst/XmlRpcServer/XmlRpcServer.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core,
|
||||
XmlRpc;
|
||||
|
||||
file
|
||||
XmlRpcServer.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
5
upptst/XmlRpcServer/init
Normal file
5
upptst/XmlRpcServer/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _XmlRpcServer_icpp_init_stub
|
||||
#define _XmlRpcServer_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#include "XmlRpc/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue