Open-source IM tool compilation and environment building strategy

Source: Internet
Author: User
Tags domain server

Open-source IM tool compilation and environment building strategy
For the sake of work, we need to check the popular open source IM clients and servers. I am engaged in C ++ and need to connect the IM platform with an existing product. Therefore, the development language of the IM platform is basically locked in C ++ or C #, after investigation, we found an excellent open-source IM platform developed in C # language, agsXMPP. In addition, an IM Client spark developed in a very good JAVA language is used as a test reference, and openfire is used for the server.

This article is not entirely my original article. In order to achieve smooth implementation, clients created on the agsXMPP open-source platform can communicate with spark from another client through the openfire server and send files to each other, I have referred to the openfire website and some other solutions on the Internet. However, I have summarized and summarized the problems I encountered throughout the process, I hope that later students will be able to get help from this article.

1. Source Code project and SVN address required for building the environment

1. The SVN address of agsXMPP is:

Svn: // svn.ag-software.de/agsxmpp/trunk

2. The SVN address of openfire is:

Http://svn.igniterealtime.org/svn/repos/openfire/trunk

3. The SVN address of spark is:

Http://svn.igniterealtime.org/svn/repos/spark/tags/spark_2_5_8

2. Compile agsXMPP

Compiling agsXMPP is simple. You only need to use Visual Studio. NET 2008 to open the relevant project file and compile it. Generally, no errors will occur.

However, the client uses the miniclient instance that comes with agsXMPP, and the server uses openfire. Therefore, we need to consider the connectivity between the two when compiling the source code. After actual verification, we find that, the source code in miniclient must be modified before smooth communication.

1. Authentication Protocol Problems

AgsXMPP in the authentication, the default use of DIGEST-MD5, but in openfire can not pass the authentication, change to PLAIN, that is, in the miniclient frmMain. in the XmppCon_OnSaslStart method of cs, remove the comments of the following two rows:

Args. Auto = false;

Args. Mechanic = agsXMPP. protocol. sasl. Mechanic. getmechanic ismname (agsXMPP. protocol. sasl. Mechanic ismtype. PLAIN );

2. Iq Section

Openfire does not support attributes of the Iq section with to. Therefore, when sending the Iq section in agsXMPP, you just need to RemoveAttribute (", find sasl/saslHandler under the source code directory of agsXMPP. in the cs file, add the following statement before calling the SendIq method:

BIq. RemoveAttribute ("");

After modification, We can smoothly authenticate the openfire server and send messages.

Iii. Compile spark

Compiling spark is also very simple. on the official website of spark and openfire, I also copied the SVN download, compilation, and debugging environment.

1. Install JDK

This does not need to be said. Note that the version must be at least 1.5. We recommend that you use the latest version 1.6.

2. Install Eclipse3.3

A) download Eclipse 3.3 from the official website (for Java developers)

B) Suppose you install eclipse in c:/program files/eclipse, enter this folder, create a desktop icon for eclipse.exe, right-click this icon, and select "properties ", open the Properties dialog box. In the "target" input box, enter the following

"C: \ Program Files \ Eclipse \ eclipse.exe"-vm "C: \ Program Files \ Java \ jdk1.6.0 \ bin \ javaw"

Anyone familiar with eclipse knows which Java VM is used for eclipse.

3. Install the Subversive plug-in for eclipse

A) Open eclipse with the icon above, and install the Subversive plug-in below. Because I use the English version of ecplipse, the following menus are all in English.

B) Click Help: Software Updates: Find and Install...

C) Click Search for new features to install and click Next.

D) Click New Remote Site...

E) Enter Subversive in the name input box and in the URL input box

Http://www.polarion.org/projects/subversive/download/1.1/update-site (http://www.eclipse.org/subversive query on the latest Subversive address)

F) Click Finish to start installing Subversive. eclipse will search for the website and display the functions you want to install in the next window.

Choose to install all the functions under Subversive SVN Team Provider Plugin and Subversive Client Libraries

G) Click Next to start the eclipse installation process. After the installation is complete, restart eclipse.

4. Use svn to download spark code

A) Click Windows: Open Perspective: Other...

B) In the displayed "Open Perspective" dialog box, select "SVN Repository handling" and click OK.

C) This is a change in the eclipse interface. On the "SVN Repositories" panel on the left, right-click and choose New: Repository Location...

D) enter the SVN address provided above at the Location of "New Repository Location" and click "Finish"

E) on the SVN Repositories panel, it will change. Expand it, find the spark option, right-click the trunk item under spark, select "Check Out", and download the spark code.

F) after the download is complete, select Window: Open Perspective: Java. On the Project Explorer panel, view the Spark Project and delete it, in the displayed dialog box, select "Do not delete contents" and find the spark folder under the working directory, which contains the spark source code. In fact, we can obtain the source code by packing and downloading the source code, but we will not be able to track the latest source code upgrade of spark in time, with version management, you can also easily compare the differences with the original version during the spark modification process. Therefore, we strongly recommend that you use SVN for download.

5. Create a Spark Project

A) Click Window: Open Perspective: Java menu.

B) In the Project Explorer window, if you delete a spark Project, you will be asked if you want to delete the file or not.

C) Select File: New: Project ..., select Java: Java Project, select "Create Project from existiing source" in the New Java project window, and add the folder where the spark file is located.

D) enter spark in "project name", which must be the same as the folder name.

E) Click Finish.

6. Generate Spark

A) Click Window: Show View: Ant.

B) Right-click the Ant panel and select Add Buildfiles.

C) Expand spark: build folder, select build. xml, and click "OK"

D) on the Ant panel, expand Spark and double-click "release". After a period of time, the system prompts "Build Successful ".

7. Create Project Builder

A) Click Run: Open Debug Dialog.... The "Run" window appears.

B) Select "Java Application" and click "New.

C) on the "Main" tab, replace New_configuration with Spark or another one.

D) Click Project: Browse, select Spark, and click OK.

E) Click the Main class: Search button, select the class Startup-org.jivesoftware.launcher where main is located, and then click OK

F) we recommend that you select Stop in main.

G) Click the Classpath tab and select User Entries to make the Advanced... button available.

H) Click the Advanced button. In the displayed Advanced Options window, select Add Folders, click OK, select the spark: src: resources Folder in the Folder Selection window, and click OK.

I) Select the Common tab, check the Debug and Run boxes.

J) Click Apply and then Close.

8. Run/Debug

Click Run: Open Run Dialog..., select Spark in the pop-up Dialog box, and click Run.

9. note that GSSAPIConfiguration is found in actual compilation. the java file is stored in the src \ java directory, causing ant compilation to fail. The GSSAPIConfiguration error cannot be found in the report. In fact, the source code should be moved to (instead of being copied) src \ java \ org \ jivesoftware directory.

4. Compile openfire

1. Install JDK

Needless to say, note that the version should be at least 1.5. We recommend that you use the latest version 1.6.

2. Install Eclipse3.3

A) download Eclipse 3.3 from the official website (for Java developers)

B) Suppose you install eclipse in c:/program files/eclipse, enter this folder, create a desktop icon for eclipse.exe, right-click this icon, and select "properties ", open the Properties dialog box. In the "target" input box, enter the following

"C: \ Program Files \ Eclipse \ eclipse.exe"-vm "C: \ Program Files \ Java \ jdk1.6.0 \ bin \ javaw"

Anyone familiar with eclipse knows which Java VM is used for eclipse.

3. Install the Subversive plug-in for eclipse

A) Open eclipse with the icon above, and install the Subversive plug-in below. Because I use the English version of ecplipse, the following menus are all in English.

B) Click Help: Software Updates: Find and Install...

C) Click Search for new features to install and click Next.

D) Click New Remote Site...

E) Enter Subversive in the name input box and in the URL input box

Http://www.polarion.org/projects/subversive/download/1.1/update-site (http://www.eclipse.org/subversive query on the latest Subversive address)

F) Click Finish to start installing Subversive. eclipse will search for the website and display the functions you want to install in the next window.

Choose to install all the functions under Subversive SVN Team Provider Plugin and Subversive Client Libraries

Click Next to start the eclipse installation process. After installation, restart eclipse.

4. Use svn to download Openfire code

G) Click Windows: Open Perspective: Other...

H) in the displayed "Open Perspective" dialog box, select "SVN Repository handling" and click OK

I) This is an eclipse interface change. On the "SVN Repositories" panel on the left, right-click and choose New: Repository Location...

J) enter a http://svn.igniterealtime.org/svn/repos at the Location of New Repository Location and click Finish"

K) on the SVN Repositories panel, it will change. Expand it, find the openfire option, right-click the trunk item under openfire, select "Check Out", and download the openfire code.

After the download is complete, select Window: Open Perspective: Java. On the Project Explorer panel, you can see the openfire Project and delete it, in the displayed dialog box, select "Do not delete contents" and find the openfire folder under the working directory, which contains the source code of openfire.

5. Create an Openfire Project

F) Click Window: Open Perspective: Java menu.

G) In the Project Explorer window, if you delete an Openfire Project, you will be asked if you want to delete the file or not.

H) Select File: New: Project ..., select Java: Java Project, select "Create Project from existing source" in the New Java project window, and add the folder where the Openfire file is located.

I) enter Openfire in "project name", which must be the same as the folder name.

J) if the "Open Associated Perspective" window opens, select "Yes ";

K) Click Finish.

6. Generate Openfire

E) Click Window: Show View: Ant.

F) Right-click the Ant panel and select Add Buildfiles.

G) Expand the openfire: build folder, select build. xml, and click "OK"

H) on the Ant panel, expand Openfire XMPP Server and double-click "openfire". After a while, the system prompts "Build Successful ".

7. Create Project Builder

K) Click Run: Open Debug Dialog.... The "Run" window appears.

L) Select "Java Application" and click "New.

M) on the "Main" tab, change New_configuration to Openfire or another one.

N) Click Project: Browse, select openfire, and click OK.

O) Click the Main class: Search button, select the main class ServerStarter-org. jivesoftware. openfire. starter, and click OK.

P) we recommend that you select Stop in main.

Q) Click the Arguments tab and enter-DopenfireHome = "$ {workspace_loc: openfire}/target/openfire" in the VM parameter box ";

R) Click the Classpath tab and select User Entries to make the Advanced... button available.

S) Click the Advanced button. In the displayed Advanced Options window, select Add Folders and click OK. In the Folder Selection window, select the openfire: src: i18n Folder and click OK.

T) Click "Advanced"> "Advanced Options"> "Add Folders"> "Folder Selection", select the openfire: src: resources: jar Folder, and click "OK ".

U) Click "Advanced"> "Advanced Options"> "Add Folders"> "Folder Selection", select the openfire: build: lib: dist Folder, and click "OK ".

V) Select the Common tab, check the Debug and Run boxes.

W) Click Apply and then Close.

8. Run/Debug

Click Run: Run History: Openfire and Run: Debug History: Openfire. Click Run/Debug.

V. Problems Encountered during compilation and Solutions

1. Solve the Problem of garbled Chinese characters After openfire uses the MySQL database

Make sure that the database you created for openfire is UTF-8 encoded. The table creation statement is as follows:

Create database openfire default character set utf8 default collate utf8_general_ci;

When you have created a database, you can use:

Alter database openfire default character set utf8 default collate utf8_general_ci;

Second, when initializing the openfire database, that is, when the openfire server is configured for the first time, the connection string connecting to the database must be in the character encoding format and the UTF-8 encoding requirements must be added to the connection, set the connection string as follows:

Jdbc: mysql: // 127.0.0.1: 3306/openfire? UseUnicode = true & characterEncoding = utf8

If the installation is complete, you can change the configuration. Go to the openfire installation directory and find conf/openfire. open the following xml section and modify the serverURL.

<Database>

<DefaultProvider>

<Driver> com. mysql. jdbc. Driver </driver>

<ServerURL> jdbc: mysql: // 127.0.0.1: 3306/openfire? UseUnicode = true & amp; characterEncoding = utf8 </serverURL>

2. File Transfer Between agsXMPP and openfire

The miniclient instance of agsXMPP provides two client-client file transmission mechanisms, one is P2P direct transmission technology, that is, the receiver of the transmission opens a listening port (in this example, 1000), and the sender directly establishes a socket connection with the listening port of the receiver. The advantage of this method is: 1) the establishment of direct P2P communication can maximize the use of network bandwidth, the highest File Sending efficiency, 2) reduce the pressure on the Transit server, 3) the software architecture is relatively simple and easy to implement. However, this method also has many problems. 1) The sender and receiver must be in the same subnet and must be able to address each other. 2) if the sender or receiver is behind the NAT network or firewall, the connection cannot be established. 3) when the receiver needs to open the listening port, the firewall or anti-virus software on the local machine may be prohibited.

Another is the file transfer mechanism between two hosts that cannot be connected through the file transfer proxy mechanism. Because both clients can connect to the openfire server (probably, 1) Client A and client B are connected to server B1, 2) Client A connects to server S1, client B connects to another server B2). In either case, Client A and client B should be able to connect to A proxy server (or this proxy server may be on B1 or B2 ), therefore, we can create A file transfer proxy between A and B. Sender A sends the file to the proxy server, while B reads the file from the proxy server.

File Transfer proxy can generally use bytestream (SOCKS5 Proxy) or proxy65 proxy technology. Currently, many open-source SOCKS5 proxies and proxy65 proxies are available. However, openfire has a built-in SOCKS5 proxy server, which we can use to complete file proxy transmission tasks.

If you want to use openfire as a file transfer proxy, You need to configure the following:

1) Configure domain name for openfire

To use openfire, You need to configure the machine domain name. If the domain server is not installed in the LAN, You need to manually configure the domain name for the machine, open the C: \ WINDOWS \ system32 \ drivers \ etc \ hosts file, and add a new line:

127.0.0.1 im.openfire.com)

127.0.0.1 proxy.im.openfire.com

If other machines use the domain name to access openfire, you also need to specify the ip address corresponding to bzwang.tzsoft.com in C: \ WINDOWS \ system32 \ drivers \ etc \ hosts. Assume that the Host IP address on which openfire is installed is 192.168.1.10, A new line should be added to the hosts file:

192.168.1.10 im.openfire.com

In this way, specify the host domain name. We recommend that you configure the static ip address for the machine where openfire is installed to avoid ip address changes.

2) configure the openfire file proxy

After configuring the domain name of openfire, you can access its management interface through http, enter: http://im.openfire.com: 9090/in the browser to log on to the management interface.

On the openfire management interface, select "System Properties" to set the property xmpp. the domain value is changed to im.openfire.com, and an attribute xmpp is added. proxy. transfer. required: set the value to false.

Click the "Server Settings" tab, click "File Transfer Settings", and set its attribute to "Enable ", set the corresponding port to "7777 ".

If you want to transfer files between different transmission proxy servers, you also need to click "Server to Server (Server to Server)" on the "Server Settings" tab )", set the attribute to Enable and set the listening port to 5269 ".

Restart the openfire server.

3) modify the miniclient source code and set the transmission proxy server.

In the Miniclient source code, the source file for file transmission is frmFileTransfer. cs. At the beginning of the file, a constant string defines the name of the transmission proxy used as follows:

Const string PROXY = "proxy.im.openfire.com ";

Note that you must direct the PROXY to proxy.im.openfire.com. Because the XMPP service discovery specifies the domain name rules of the file transfer proxy, you must add "PROXY" before it; otherwise, it cannot be resolved. In addition, the IP address of the transmission proxy cannot be used directly. I wasted a lot of time to find this problem.

In addition, check the SendStreamHosts method in frmFileTransfer. cs and find the following lines:

String hostname = System. Net. Dns. GetHostName ();

System. Net. IPHostEntry iphe = System. Net. Dns. Resolve (hostname );

For (int I = 0; I <iphe. AddressList. Length; I ++)

{

Console. WriteLine ("IP address: {0}", iphe. AddressList [I]. ToString ());

// BsIq. Query. AddStreamHost (m_XmppCon.MyJID, iphe. AddressList [I]. ToString (), 1000 );

}

BsIq. Query. AddStreamHost (new Jid (PROXY), PROXY, 7777 );

Add the local address list to the stream host list, listen on port 1000, add the proxy server to the stream host list, and listen on port 7777, if you cancel the annotation, the file transmission between clients will take precedence over the P2P mode. If the client cannot be connected, the proxy mode will be used. As we mainly demonstrate how to use the proxy here, therefore, the P2P code is commented out and can be opened during actual use.

Through the above settings, we can implement File Sending and receiving between miniclient and spark clients, and in the Intranet environment, both P2P and proxy modes, the sending efficiency of large files is very high.

6. I use a commercial IM client developed by agsXMPP

In the course of learning, I basically learned how agsXMPP works, and it took me three months to use the platform, I have created an IM client that can be used in my products. Below are some of the software, which can be used for single-person chat and group chat, p2P transmission of files, server transfer of files, and other basic functions, will be considered to add voice chat and other functions.

Figure 1 Main Interface

Figure 2 single-user chat Mode

 

Figure 3 multi-user group chat Mode

 

Figure 4 view history

Figure 5 send a file

Figure 6 system settings

Currently, only one of me is working on this project, and no configuration is available for the project, so I feel that the interface is still very rough. I hope this project can be continued in the future, can make a good thing.

 

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.