Preface
As the demo version of the project draws to a close, it begins to prepare all aspects of Android. One of the most important aspects is to communicate with the server. Here we will try and evaluate Hessian under the Android platform, although it is not an official version, but there are always updates.
Link
1. Hessian Official Website:
Note: Hessian is also a lightweight binary RPC protocol with custom descriptions. As it is a binary protocol, Hessian is suitable for sending binary data and needs to be extended using other attachments.
Address: http://hessian.caucho.com/
2. hessdroid project:
Note: hessdroid is an unofficial version of the Resin Hessian Binary Remote Call framework for Android.
Address: http://code.google.com/p/hessdroid/
3. Mercurial
Note: It is a lightweight distributed version control system. I chose TortoiseHG for Windows 32bit, which is used to download hessdroid source code.
Address: http://mercurial.selenic.com/downloads/
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog: http://www.cnblogs.com
Farmer's uncle: http://www.cnblogs.com/over140/
Body
I. Preparation
1.1 download source code
Download Mercurial, right-click TortoiseHg-> Clone-> Source Path, and enterHttps://hessdroid.googlecode.com/hg/"Download.
1.2 package into jar
You can directly use eclipse to import the source code and export it as a jar. Here I export it to hessdroid. jar. If you are too lazy to export it, you can download it from here: http://download.csdn.net/source/2584651.
Ii. Communication Interface
Like WebService, prepare an interface:
Public interface BasicAPI {
Public String hello ();
}
Ii. Server
The server is Tomcat + Servlet.
2.1 import the official Hessian jar package from http://hessian.caucho.com/. the example is hessian-3.0.20.jar.
2.2 BasicService. java
Public class BasicService extends HessianServlet implements BasicAPI {
Private String _ greeting = "Hello, world ";
Public void setGreeting (String greeting)
{
_ Greeting = greeting;
}
Public String hello ()
{
Return _ greeting;
}
}
2.3 configure and accept servlet in web. xml, which is written here:
<Servlet>
<Servlet-name> hello </servlet-name>
<Servlet-class> com. BasicService </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-name> hello </servlet-name>
<Url-pattern>/hello. do </url-pattern>
</Servlet-mapping>
Iii. Client
3.1 create an Android project and import hessdroid. jar (do not confuse it. It is the jar package generated by your own package ).
3.2 Add a button on the interface and add a click event:
Public void OnClick11 (View view)
{
String url = "http: // 192.168.1.1: 8080/HessianServer/hello. do ";
HessianProxyFactory factory = new HessianProxyFactory ();
Try {
Factory. setDebug (true );
Factory. setReadTimeout (5000 );
BasicAPI basic = (BasicAPI) factory. create (BasicAPI. class, url, getClassLoader ());
Toast. makeText (this, "Call Result:" + basic. hello (), Toast. LENGTH_LONG). show ();
} Catch (MalformedURLException e ){
E. printStackTrace ();
}
}
3.3 successful:
Maintenance
2010-11-11
Experience shared by jiangcoco: The hessianConncectionException error occurs when you connect to the server. The simulator is good. It is obvious on the real machine and may be caused by network reasons. In this case, set the timeout time to a little later.
2011-8-9
Remember to add permissions: <uses-permission android: name = "android. permission. INTERNET"/>
2011-9-
Add two Hessian articles:
Hessian lightweight binary Remote Call framework
Spring technology insider 18 -- Spring uses Hessian for remote calls
End
Pay attention to the official test link "http://hessian.caucho.com/test/test" is not connected, has been an error can not find hello this method, and later switch to their own server after all of a sudden success. A good start is half the success. Next we will test the data transfer, big data volume, and whether there are any Chinese problems.