XMPP (II)-introduction and personal experience of the android client (like QQ) based on asmack + openfire, xmppasmack
The first article on XMPP-after the openfire was built, I have been catching up with this android client based on asmack + openfire which I want to introduce in this article, which has paid a lot of effort, A lot of students are waiting anxiously (narcissistic), so they are in a hurry. Now we have developed a relatively basic version, and many functions are not complete, however, if you are interested in this project, you can refer to it for research, ask questions, and learn together, you can continue to follow ^-^
Now, let's introduce the functions implemented in this project:
1. registration;
2. log on;
3. Search for people by nickname;
4. Add a friend (send a friend application, and the other party receives a friend request and agrees to the request before becoming a friend );
5. The interface includes the list of recent contacts and friends;
6. chat: currently, the supported types include text, images, positions, and dynamic expressions. (The path and coordinates of the images are fixed in this preliminary version );
7. exit;
8. No Logon; (if one logon succeeds, the system will automatically log on when the software is started next time );
Interface:
Some functions on the interface are not implemented in this version, and some details are processed. Optimization on the code will be improved step by step and published in a later blog.
Next, the chat mode is enabled. In fact, there are not many apps for chatting, except for QQ, which we are familiar, other social applications basically include chatting in the APP, and this QQ-style friend adding is also often transformed into attention in today's social applications, if you are followers or fans, such as well-known Weibo and Momo, there will be more unknown ones. Because XMPP, mutual chat does not require the two sides to be friends, you only need to know the JID of the other side to receive and send messages. Therefore, many applications have taken a fancy to this point, to achieve the following functions in the application, such as follow and fans. The following functions can be implemented through web services, while XMPP only serves as a point-to-point chat function, therefore, you don't have to worry about inviting friends that come with xmpp. You have agreed to apply for a friend and obtained a friend list. You only need to get a general understanding of it. The focus is on the implementation of the chat process, and the stability of the client-server connection (for example, how to re-connect the client to the server, XMPP's built-in re-connection is not stable), and so on. Of course, if some students have a strong research spirit or the company has a demand, so you can study it in depth.
There are many servers that support the XMPP protocol. openfire is a familiar one. When a project decides to use openfire as the server, if you want to implement more complex functions or functions that meet your requirements, you need to transform openfire because openfire has some limitations, but fortunately it is open-source. In addition, generally, if you use openfire for social networking software, there are two servers, one is your own web server, and the other is openfire server, such as a friend profile picture, nickname, gender, age, address, similar to Momo's photo wall and other information data can be accessed through the web service. You only need to match the web database with the user ID of the database, instead of relying on openfire itself, the access to these materials cannot be achieved. When doing this project, I planned to combine web and of to implement more complex and practical functions, but I finally gave up, so the workload should be too heavy, I don't have that much energy and time! Therefore, as mentioned above, we can focus on chatting and how to combine the large amount of information stored on the web with of. This is the focus! (-- Personal opinion)
Now let's talk about how to transmit information such as videos, audios, and videos through xmpp during the chat process. I also frequently asked some people to learn how to transmit the xmpp voice, how to transfer files and so on (but now xmpp seems to support file transfer, but I have never tried it). In fact, we only need to think carefully and think about the solution, what is the fastest and simplest way to upload xmpp data? Of course it's a string! What can be contained in a string? Everything is available! Therefore, we can put all the information we want into the string for transmission. After the recipient receives the message, it parses it to get everything you want, such as in this project, the implementation of the image and the location message is to combine the image path or location coordinates with the receiver and the sender information at a specific interval and assemble it into a string and send it as the body of the message (for example: recipient * sender * Message Type * message content * sending time *... Wait). After receiving the message, the other party splits it into "*" to get all the information. Why? Therefore, we only need the path for image audio and video types. How can we obtain the path? As I mentioned above, in combination with the web service, I now upload images and voice to the web server to obtain the path after the upload is successful (this is not difficult ), then, the path is sent to the recipient as a string. After receiving the message, the recipient parses the Message Type and downloads the image or voice according to the path... For details, refer to the implementation process of this project!
Well, let's talk about it here first. We will continue this blog later, and this project will continue to be updated!
Project Source: http://download.csdn.net/detail/baiyuliang2013/8391863
Note: after the source code is deployed, find Consts. in java, XMPP_HOST needs to be changed to its own IP address (the end name should be the same as the local IP address. For details, refer to the previous article -- openfire installation and setup). In addition: the client must be supported by the server, that is, openfire. If the client is not installed, it cannot run.