PHP Server
[PHP]View PlainCopy
- <?php
- require_once (' src/hprose.php ');
- function Hello ($name) {
- echo "Hello $name!";
- return "Hello $name!";
- }
- function E () {
- throw New Exception ("I am Exception");
- }
- function ee () {
- require ("Andot");
- }
- function Asynchello ($name, $callback) {
- Sleep (3);
- $callback ("from Server,hello async $name!");
- }
- $server = new Hprosehttpserver ();
- $server->seterrortypes (E_all);
- $server->setdebugenabled ();
- $server->addfunction (' hello ');
- $server->addfunctions (array (' e ', ' ee '));
- $server->addasyncfunction (' Asynchello ');
- $server->addfilter (new Hprosejsonrpcservicefilter ());
- $server->start ();
PHP Client
[PHP]View PlainCopy
- <?php
- Require_once (' src/hprose.php ');
- $test = New Hprosehttpclient ("http://localhost/hprose/http_server.php");
- echo ' <br/> ';
- Var_dump ($test->invoke ("Hello", $args, 0, hproseresultmode::serialized, 0));
- echo ' <br/> ';
- Var_dump ($test->invoke ("Hello", $args, 0, Hproseresultmode::raw, 0));
- echo ' <br/> ';
- Var_dump ($test->invoke ("Hello", $args, 0, Hproseresultmode::rawwithendtag, 0));
- echo $test->asynchello ("World");
- echo ' <br/> ';
- $test->asynchello ("World", function ($result)
- {
- echo "From client result:";
- Var_dump ($result);
- });
- echo ' <br/> ';
- /*
- $test->dnslookup ("www.baidu.com", Function ($result, $args) {
- echo "Result:";
- Var_dump ($result);
- echo "args:";
- Var_dump ($args);
- });
- */
- ?>
Java Client
[Java]View PlainCopy
- Package hprose.hello.client;
- Import hprose.client.HproseHttpClient;
- Import java.io.IOException;
- Public class Helloclient {
- public static void Main (string[] args) throws IOException {
- Hprosehttpclient client = new Hprosehttpclient ();
- Client.useservice ("Http://10.0.0.100:9090/hprose_demo/Hello");
- String result = (string) client.invoke ("SayHello", new object[] { "Hprose"});
- SYSTEM.OUT.PRINTLN (result);
- result = (String) client.invoke ("SayHello", new object[] { "China"});
- SYSTEM.OUT.PRINTLN (result);
- System.out.println (Client.invoke ("Add",new object[]{,316});
- }
- }
[Java]View PlainCopy
- Package hprose.hello.client;
- Import java.io.IOException;
- Import hprose.client.HproseHttpClient;
- Public class Testphpclient {
- public static void Main (string[] args) throws Exception {
- Hprosehttpclient client = new Hprosehttpclient ();
- Client.useservice ("http://10.0.0.105/hprose/http_server.php");
- String result = (string) client.invoke ("Hello",
- New object[] { "Hprose from Java Client"});
- SYSTEM.OUT.PRINTLN (result);
- System.out.println (Client.invoke ("Asynchello",new object[] { "Hprose from Java Client"}));
- }
- }
Delphi Client:
[Delphi]View PlainCopy
- Unit UNIT4;
- Interface
- Uses
- Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
- Dialogs, Stdctrls, Hprosehttpclient, hproseclient;
- Type
- TFORM4 = Class (Tform)
- Button1:tbutton;
- Hprosehttpclient1:thprosehttpclient;
- Button2:tbutton;
- procedure Button1Click (sender:tobject);
- procedure Button2click (sender:tobject);
- Private
- {Private declarations}
- Public
- {public declarations}
- end;
- Var
- FORM4:TFORM4;
- Implementation
- {$R *.DFM}
- Procedure TFORM4. Button1Click (Sender:tobject);
- Begin
- HproseHttpClient1. Useservice (' Http://10.0.0.100:9090/hprose_demo/Hello ');
- ShowMessage (HproseHttpClient1. Invoke (' SayHello ', [' World Chinese ']);
- ShowMessage (HproseHttpClient1. Invoke (' Add ', [63]));
- End
- Https://raw.githubusercontent.com/andot/hprose/master/doc/1.3/docx/pascal.docx
- Procedure TFORM4. Button2click (Sender:tobject);
- Begin
- HproseHttpClient1. Useservice (' http://10.0.0.105/hprose/http_server.php ');
- ShowMessage (HproseHttpClient1. Invoke (' Hello ', [' World Time ']);
- ShowMessage (HproseHttpClient1. Invoke (' Asynchello ', [' xxx ']));
- End
- End.
SOURCE project: Http://pan.baidu.com/s/1o6vF1qE
http://blog.csdn.net/earbao/article/details/46501671
Hprose RPC usages (with examples of both Java and Delphi clients)