Location Awareness Service Based on instant messaging and LBS technology (III): Build openfire SERVER + Test 2 IM clients

Source: Internet
Author: User
Tags management studio microsoft sql server management studio sql server management sql server management studio

It consists of four chapters:

1. Instant Messaging solutions in the Java Field

2. Build an openfire Server

3. Use the client to test the openfire server we set up

4. Smack and asmack


I. Java instant messaging solutions


Openfire + spark + smack can be considered for Java instant messaging solutions.

1. openfire is an instant messaging server version based on the jabber protocol (XMPP). The latest version is 3.6.4. You can download it online.Source code.

2. The instant messaging client can use spark2.5.8, which is currently the latest release version. After testing, it is found that the previous version is supported by video.

3. smack is the real-time communication client programming library. It can use the smack API to send messages to openfire registered users, obtain the response messages of the users through the listener, and even implement automatic response robots, we will use this API for backdoors.

2. Build an openfire Server


2.1 preparations: configure the host domain name

To use openfire, You need to configure the machine domain name. Open the c: \ windows \ system32 \ drivers \ etc \ hosts file and add a new line: im.comit.com.cn
To access openfire through a domain name on other machines, you also need to specify the IP address corresponding to im.comit.com.cn in C: \ windows \ system32 \ drivers \ etc \ hosts. For example, my lan ip address is, A new line should be added to the hosts file: im.comit.com.cn

You can ping the domain name im.comit.com.cn to verify that the configuration is correct:


2.2 Preparation: Create a database required for running openfire

Download openfire: openfire requires Java runtime. Because my machine already has a Java development environment, I downloaded the free installation version zip package.

After downloading and decompressing, my directory is: D: \ technology \ XMPP \ openfire.

You need to create the database required to run openfire: I have installed sqlserver 2005 on my computer. Open the D: \ technology \ XMPP \ openfire \ resources \ database directory:

Open Microsoft SQL Server Management studio to create the database openfire and run the openfire_sqlserver. SQL script:

Some tables are truncated here.

Because the openfire installation package does not have a built-in JDBC driver for sqlserver, You need to download sqljdbc. jar from the Internet and copy it to the following directory: D: \ technology \ XMPP \ openfire \ Lib.

2.3 start to install openfire

After the table is created, run openfire.exe in the bindirectory.

Select launch admin to open the administrator interface:

Select Simplified Chinese and continue to the next step:

Enter the domain name configured in 2.1: im.comit.com.cn. The default port is port. Continue:

In this step, select the standard database and continue:

Select sqlserver

DriverProgramClass input: COM. Microsoft. sqlserver. JDBC. sqlserverdriver

Database URL: JDBC: sqlserver: //; databasename = openfire

Access username SA, password xxxxxx, other default. Click to continue:

Select "Initial Settings" and continue:

Enter the game number and password here. Note: This step is to create an admin account and remember the password. Continue:

The system prompts that openfire has been installed successfully.

In Microsoft SQL Server Management studio, open the table ofuser and you will see the created admin account:

At this time, do not click "log on to the Management Console". logon will certainly fail. You need to switch to this page:

Click "Stop" and then "start". After the restart is successful, click "launch admin" to go To the logon page:

Enter Admin and the password you just created, and log on:

From the administrator interface, we can view the server name im.comit.com.cn, and manage user groups and users:

Here, insert a test user through the Management Interface (then the user's jid is: teat@im.comit.com.cn, the definition of the jid in Article 2ArticleThe XMPP protocol is introduced in the following sections ).

So far, the openfire server has been basically set up successfully.


3. Use the client to test the openfire server we set up


Main test cases include: connecting to the openfire server, registering users on the client, adding friend requests to different XMPP-based clients, and sending instant messages.

1. Spark client: XMPP-based client of the same open-source organization as openfire

2. sparkweb: web-based XMPP Client

3. ruyitong (rooyee message, open source developed by domestic companies based on XMPP, support file, audio, video chat, a powerful function of a software,: http://rooyee.biz/a/xiazaizhongxin/ruanjianxiazai/index.html)

Start testing:


When installing the openfire server, we created the account test. Now we use the spark client to apply for an account Test2. Note that the server enters im.comit.com.cn. After the creation is successful, log on.

Open the table ofuser in Microsoft SQL Server Management studio and you will see the created Test2 account:

The Logon Setting of the rooyee message is similar to that of spark. We use the test account to log on to the rooyee message.

After both software are successfully logged on. Use spark to log on to Test2 and send a request to add a contact to the test logged on by the rooyee message.

In the lower-right corner of the desktop, the request dialog box for Test2 is displayed.

After agreeing to the request, you can view the online information of both parties and the registration information of the other party in the contact list.


The following tests the communication between two heterogeneous clients (spark is a Java client, and rooyee message is a client developed using Delphi, but both are based on XMPP protocol ).

The message of the spark client.

The message box of the rooyee message.

Open the openfire background at the same time, and we can see the reply information of both:

Now both the server and client are ready to pass the test.

We can find that the XMPP protocol is open.


Iv. Smack and asmack

1. The smack API is a complete open-source api library that implements the XMPP protocol and supports files, audios, videos, and other messages. You can use this api library for secondary development.

2. Because smack does not officially implement the mobile version of the API, the third party provides an open-source smack-based anadorid API: asmack (Android Build Environment and patches for smack ). On Android, you can use this API to develop an XMPP-based instant messaging application.

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.