Hprose RPC usages (with examples of both Java and Delphi clients)

Source: Internet
Author: User
Tags php server vars

PHP Server

[PHP]View PlainCopy
  1. <?php
  2. require_once (' src/hprose.php ');
  3. function Hello ($name) {
  4. echo "Hello $name!";
  5. return "Hello $name!";
  6. }
  7. function E () {
  8. throw New Exception ("I am Exception");
  9. }
  10. function ee () {
  11. require ("Andot");
  12. }
  13. function Asynchello ($name, $callback) {
  14. Sleep (3);
  15. $callback ("from Server,hello async $name!");
  16. }
  17. $server = new Hprosehttpserver ();
  18. $server->seterrortypes (E_all);
  19. $server->setdebugenabled ();
  20. $server->addfunction (' hello ');
  21. $server->addfunctions (array (' e ', ' ee '));
  22. $server->addasyncfunction (' Asynchello ');
  23. $server->addfilter (new Hprosejsonrpcservicefilter ());
  24. $server->start ();


PHP Client

[PHP]View PlainCopy
  1. <?php
  2. Require_once (' src/hprose.php ');
  3. $test = New Hprosehttpclient ("http://localhost/hprose/http_server.php");
  4. echo ' <br/> ';
  5. Var_dump ($test->invoke ("Hello", $args, 0, hproseresultmode::serialized, 0));
  6. echo ' <br/> ';
  7. Var_dump ($test->invoke ("Hello", $args, 0, Hproseresultmode::raw, 0));
  8. echo ' <br/> ';
  9. Var_dump ($test->invoke ("Hello", $args, 0, Hproseresultmode::rawwithendtag, 0));
  10. echo $test->asynchello ("World");
  11. echo ' <br/> ';
  12. $test->asynchello ("World", function ($result)
  13. {
  14. echo "From client result:";
  15. Var_dump ($result);
  16. });
  17. echo ' <br/> ';
  18. /*
  19. $test->dnslookup ("www.baidu.com", Function ($result, $args) {
  20. echo "Result:";
  21. Var_dump ($result);
  22. echo "args:";
  23. Var_dump ($args);
  24. });
  25. */
  26. ?>


Java Client

[Java]View PlainCopy
  1. Package hprose.hello.client;
  2. Import hprose.client.HproseHttpClient;
  3. Import java.io.IOException;
  4. Public class Helloclient {
  5. public static void Main (string[] args) throws IOException {
  6. Hprosehttpclient client = new Hprosehttpclient ();
  7. Client.useservice ("Http://10.0.0.100:9090/hprose_demo/Hello");
  8. String result = (string) client.invoke ("SayHello", new object[] { "Hprose"});
  9. SYSTEM.OUT.PRINTLN (result);
  10. result = (String) client.invoke ("SayHello", new object[] { "China"});
  11. SYSTEM.OUT.PRINTLN (result);
  12. System.out.println (Client.invoke ("Add",new object[]{,316});
  13. }
  14. }

[Java]View PlainCopy
  1. Package hprose.hello.client;
  2. Import java.io.IOException;
  3. Import hprose.client.HproseHttpClient;
  4. Public class Testphpclient {
  5. public static void Main (string[] args) throws Exception {
  6. Hprosehttpclient client = new Hprosehttpclient ();
  7. Client.useservice ("http://10.0.0.105/hprose/http_server.php");
  8. String result = (string) client.invoke ("Hello",
  9. New object[] { "Hprose from Java Client"});
  10. SYSTEM.OUT.PRINTLN (result);
  11. System.out.println (Client.invoke ("Asynchello",new object[] { "Hprose from Java Client"}));
  12. }
  13. }


Delphi Client:

[Delphi]View PlainCopy
  1. Unit UNIT4;
  2. Interface
  3. Uses
  4. Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, Stdctrls, Hprosehttpclient, hproseclient;
  6. Type
  7. TFORM4 = Class (Tform)
  8. Button1:tbutton;
  9. Hprosehttpclient1:thprosehttpclient;
  10. Button2:tbutton;
  11. procedure Button1Click (sender:tobject);
  12. procedure Button2click (sender:tobject);
  13. Private
  14. {Private declarations}
  15. Public
  16. {public declarations}
  17. end;
  18. Var
  19. FORM4:TFORM4;
  20. Implementation
  21. {$R *.DFM}
  22. Procedure TFORM4.  Button1Click (Sender:tobject);
  23. Begin
  24. HproseHttpClient1.  Useservice (' Http://10.0.0.100:9090/hprose_demo/Hello ');
  25. ShowMessage (HproseHttpClient1.  Invoke (' SayHello ', [' World Chinese ']);
  26. ShowMessage (HproseHttpClient1.  Invoke (' Add ', [63]));
  27. End
  28. Https://raw.githubusercontent.com/andot/hprose/master/doc/1.3/docx/pascal.docx
  29. Procedure TFORM4.  Button2click (Sender:tobject);
  30. Begin
  31. HproseHttpClient1.  Useservice (' http://10.0.0.105/hprose/http_server.php ');
  32. ShowMessage (HproseHttpClient1.  Invoke (' Hello ', [' World Time ']);
  33. ShowMessage (HproseHttpClient1.  Invoke (' Asynchello ', [' xxx ']));
  34. End
  35. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.