Java Remote Call PHPRPC for Java example
PHPRPC is a lightweight, secure, cross-network, cross-lingual, cross-platform, cross-domain, cross-field, multi-tiered, support-enabled, service-oriented, high-performance remote procedure call protocol that supports the transfer of reference parameters, supports content output redirection, supports hierarchical error handling, and supports session.
Phprpc for Java needs to implement the client and server side separately, now give a concrete example
For example, server side is http://localhost:8080/server/, server side is http://localhost:8080/client/
We need to build two projects for both server and client respectively. Then the client and server side are implemented separately.
1. Server-side implementation:
1) Create an implementation class:
public class MyHello {
public string Say (string name) {
System.out.println ("Hello world!!");
Return "Hello" +name;
}
}
2) Publishing Service:
Create a new JSP with the name hello.jsp, so its URL is: http://localhost:8080/server/hello.jsp
hello.jsp content is:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "UTF-8"%>
<% @page import= "Org.phprpc.PHPRPC_Server"%>
<% @page import= "test. MyHello "%>
<%
MyHello hello=new MyHello ();
Phprpc_server server=new phprpc_server ();
Server.add (hello);
Server.start (Request,response);
%>
So it's ready for release.
2. Client implementation:
1) Define the interface, and the server implementation class corresponding to the name Hello
Public interface Hello {
public string Say (string name);
}
2) After the step is completed, we can call it remotely, create a class, and name it as Test.java
public class test{
public static void Main (string[] args) {
Phprpc_client client=new phprpc_client ("http://localhost:8080/server/hello.jsp");
Hello hello= (Hello) client.useservice (hello.class);
System.out.println (Hello.say ("Java_kabanban"));
}
When you run Test.java, you can achieve the desired result, output: Hello Java_kabanban
is not very useful ah!!
If you are interested, you can discuss the discussion!!
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.