PHPRPC Simple example

Source: Internet
Author: User
Simple PHPRPC example & nbsp; PHPRPC is a lightweight, secure, cross-Internet, cross-language, cross-platform, cross-environment, cross-domain, support for transmission of complex objects, support for parameter reference, and support high-performance remote process call protocol that supports content output redirection, hierarchical error processing, session-oriented, and service-oriented. Official PHPRPC Simple example
PHPRPC is a lightweight, secure, cross-Internet, cross-language, cross-platform, cross-environment, cross-domain, support for transmission of complex objects, support for parameter reference, and support high-performance remote process call protocol that supports content output redirection, hierarchical error processing, session-oriented, and service-oriented.
Official Homepage: http://www.phprpc.org/zh_CN/
The official website provides a detailed introduction to various versions, so it is easy to get started. The following is an example of my demo. It takes about 30 minutes from reading the document to developing the first demo.
I am using the java version. I will not repeat the previous installation steps. please refer to the official documentation.
1. write Service interfaces and implementation classes
public interface ServiceI {public String say(String name);public Errors showError(String info);}

public class FirstService implements ServiceI{@Overridepublic String say(String name) {String res = "Hello, "+name+" from PHPRPC";return res;}public Errors showError(String info){Errors er = null;er = new Errors();er.setId("1111");er.setMsg("phprpc make error:"+info);return er;}}

public class Errors implements Serializable{private String id;private String msg;public Errors(){}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}}

2. publish services through Servlet
public class PhprpcGloabService extends HttpServlet {@Overrideprotected void service(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {[b]PHPRPC_Server server = new PHPRPC_Server();FirstService first = new FirstService();server.add(first);server.start(req, res);[/b]}}

Configure the web. xml file and place the services to be published in the rpcservice space
 
 
  
   
GloabService
  
  
   
Com. smartcoms. service. PhprpcGloabService
  
  
   
1
  
 
 
  
   
GloabService
  
  
   
/Rpcservice /*
  
 

The service has been released!
3. write client programs
I use a jsp page as a client to access the Service
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <% @ page import = "org. phprpc. * "%> <% @ page import =" com. smartcoms. web. UIElement. errors "%> <% @ page import =" com. smartcoms. service. serviceI "%>
 Phprpc debugging<% PHPRPC_Client client = new PHPRPC_Client ("http: // localhost: 8082/smartcoms/rpcservice/GloabService"); ServiceI service = (ServiceI) client. useService (ServiceI. class); out. println (service. say ("China"); Errors er = service. showError ("info"); out. println (er. getId (); out. println (er. getMsg (); %>

PHPRPC is easy to use and can implement fast Web Service applications. In other aspects, more application environments need to be implemented and evaluated.

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.