Android message push (I)-androidpn (XMPP protocol) demo version officially launched

Source: Internet
Author: User

Preface:

Recently, the company needs Android message push. Many examples of message push on the Internet are unavailable.

After a period of research, we finally run the example. Now we can share and learn together.
In the downloaded file, double-click the run. BAT file in the bin directory to run it. Then, enter

Http: // 127.0.0.1: 7070. If you run the client in eclipse, you can see it on the server. this is very simple, not the focus of this article. now the main thing is to download the server source code.

Build up, and then deploy to myeclipse to run, of course, can download the androidpn official website (http://sourceforge.net/projects/androidpn/files ),
You can also download the program I have adjusted. now share the source code to everyone, http://download.csdn.net/detail/johnny901114/4410546
It should be noted that the MySQL database is used in my source code, so the reader needs to install the MySQL database on the PC. I will not talk about the data here. of course, it is better to understand spring and hibernate. In this case, it is more convenient.

However, there may still be people who do not understand hibernate. In order to make it run well, let's simply talk about it.


Process:

First open JDBC. properties:

# JDBC Configuration
Jdbcdriverclassname = com. MySQL. JDBC. Driver
Jdbcurl = JDBC: mysql: // localhost/test? Useunicode = true & characterencoding = UTF-8 & zerodatetimebehavior = converttonull
Hibernate. dialect = org. hibernate. dialect. mysql5innodbdialect
Jdbcusername = root
Jdbcpassword =
# DBCP pool settings
Jdbcinitialsize = 5
Jdbcmaxactive = 10
Jdbcmaxidle = 5
Jdbcmaxwait = 30000
Jdbcvalidationquery = select 1

------------------------------------------------------------

Jdbcdriverclassname: name of the database Driver Class
Jdbcurl: indicates the URL to connect to the database. test indicates the database name.
Hibernate. Dialect: Database Dialect
Jdbcusername and jdbcpassword: MySQL user name and password

I will not talk about anything else.

If not, after the server is successfully started, enter http: // localhost: 8080/in the browser/

The following interface is displayed:


Then, run the client code. Note that you should change xmpphost in androidpn. properties to your lan ip address. Run the command as shown in:


Then, you can see the connection between the mobile phone and the server on the users interface in the browser. For example:



Then, you can send a message to the client on the notifications page:


The client receives the notification:


The content in the notification is the content entered by the message on the webpage. The OK button is the content of the URI on the webpage.


Finally, there is another problem. When the server is restarted, the client will not be able to connect to the server, unless the android Background Service

Turn it off, and restart it. Add the following red code to xmatrix Manager:

Private void addtask (runnable ){
Log. D (logtag, "addtask (runnable )...");
Tasktracker. Increase ();
Synchronized (tasklist ){
If (tasklist. isempty ()&&! Running ){
Running = true;
Futuretask = tasksubmitter. Submit (runnable );
If (futuretask = NULL ){
Tasktracker. decrease ();
}
} Else {
// After the server is restarted, the client cannot connect to the androidpn server.
Runtask ();

Tasklist. Add (runnable );
}
}
Log. D (logtag, "addtask (runnable)... done ");
}




Certificate ----------------------------------------------------------------------------------------------------------------------------------------------------------



Follow-up:


Today, the company finally deployed the androidpn server to the server, and finally went online.

The general steps are as follows:

1. Run the war package of the server program through myeclipse, visit the Tomcat homepage, and upload the war package to the Tomcat server.


Click Tomcat Manager to display the following page:

Login Failed by default, You need to configure in the tomcat-user.xml file, add the following configuration to the file:

<role rolename="manager-gui"/><user username="tomcat" password="tomcat" roles="manager-gui"/>


Then upload the war package to Tomcat through the following interface:


Note that you need to have a database on the server computer (MySQL in my memory) and a database corresponding to androidpn (the database name here is test ). pay attention to the username and password of the database.

2. Assume that the server has been able to access the client, you need to set the androidpn of the client. the xmpphost value of the properties file is changed to the Host Name of your server, assuming that your server access address is: http://push.android.net: 8080/, then change the xmpphost value to push.android.net


3. Make sure to open port 8080 and port 5222. (This is what people on the server do, but they do not understand it very well ).

Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------



Follow-up 2: questions about androidpn (2012.8.16)


1. If you change the random UUID code generated by the client to the device ID or Mac (device/MAC) as the user name, a duplicate insertion error will occur.

2. Clear (or reinstall) The client data, so there will be no data in sharedpre. However, the server has the device ID of our mobile phone, then start the program and there will be repeated inserts.


Therefore, the solution is to check whether the user exists when saving the user on the server.

The reason is that the client has registered it with the server and whether username and password exist in sharedpreferences.


Certificate -------------------------------------------------------------------------------------------------------------------------------------------------


Subsequent 3: Other Android push methods (3.1.3.1.4)


Other push solutions:


1> if you want convenience and low cost, we recommend that you use Aurora push, as long as you integrate its official SDK. domestic value is more famous, push text is free, you can also push the media (charges), the official website for http://www.jpush.cn/


2> Android official website provided the latest, GCM, is used to replace c2dm, its official website for http://developer.android.com/google/gcm/index.html


3> you can use Java NiO to implement your own server. My colleagues told me that its manager wrote a push server through Java NiO that could receive about 30 million concurrent requests. He was trying to write one, if there is progress, we will share it with you. at the same time, we can study Apache project Mina. This project encapsulates Java NiO.


4> when XMPP protocol can be used for pushing, I have also written a simple one-to-one instant chat software.


5> You can also use the mqtt protocol to push messages.

Client: https://github.com/tokudu/AndroidPushNotificationsDemo

Https://github.com/tokudu/PhpMQTTClient Server

For more information about mqtt: Android message push (2)-mqtt-based push function



If you have other questions, leave a message. Thank you!

Reprinted please indicate the source: http://blog.csdn.net/johnny901114/article/details/7715758




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.