Objective
OpenFire is a chat server, like the QQ service. The essence is a socker servers.
OpenFire communication protocol is XMPP, what is XMPP reference encyclopedia Https://baike.baidu.com/item/XMPP/3430617?fr=aladdin
OpenFire three part of the project
1. Server---> 2. Desktop client Spark---> 3.smack (API Client)
1. Service-side structure
A.plugins (plugin):
1. The Official plugin
2. Develop your own plugins
Feature Overview: For example, registered users.
B.web version of the management side
2. Desktop version of Client spark
A. Similar to QQ client, still useless
3.smack (API Client)
A.API Library, programmers all understand.
Installation article
Download OPENFIRE-4.1.5-1.NOARCH.RPM,JDK Environment 1.8
#安装
RPM-IVH openfire-4.1.5-1.noarch.rpm
#启动
Systemctl Restart OpenFire
#浏览器打开
http://ip:9090
The official Rest API plugin uses
#安装rest API
REST API Plug-ins can add users in the background, etc., view documents in detail
Python Invocation Example:
#coding =utf-8import Requestsimport jsontou1 = {"Authorization": "Pymxg12rqqdj2vfy", "Accept": "Application/json"}TOU2 = {"Authorization": "Pymxg12rqqdj2vfy", "Content-type": "Application/json"}tou3 = {"Authorization": "Pymxg12rqqdj2vfy "," Content-type ":" Application/xml "}def serach_user (user): url =" http://192.168.0.110:9090/plugins/restapi/v1/ Users?search={user} ". Format (user=user) r1 = Requests.get (url,headers=tou1) print r1.textdef create_user (user): Ur L = "http://192.168.0.110:9090/plugins/restapi/v1/users" r1 = requests.post (URL, headers=tou2,data=user) print R1.te XT Print R1.status_codedef send_broadcast_message (message): url = "Http://192.168.0.110:9090/plugins/restapi/v1/mess Ages/users "r1 = requests.post (URL, headers=tou3,data=message) print r1.status_codeif __name__ = = ' __main__ ': # C _user1 ={"username": "New1", "Password": "P4ssword"} # C_user1 = Json.dumps (c_user1) # Create_user (c_user1) Messa GE = "" "<?xml version=" 1.0 "encoding=" UTF-8 "standalone=" yes "><message><body>your message hello</body></message>" "Send_ Broadcast_message (Message)
Smack (API Client) use
Create a Mavn project.
Pom.xml add
<dependency>
<groupId>Org.igniterealtime.smack</groupId> <Artifactid>Smack-java7</Artifactid> <version>4.1.1</version> <Exclusions> <exclusion> <groupId>Xpp3</groupId> <Artifactid>Xpp3</Artifactid> </exclusion> </Exclusions> </Dependency> <Dependency> <groupId>Xpp3</groupId> <Artifactid>Xpp3</Artifactid> <version>1.1.3.4.O</version> </Dependency> <Dependency> <groupId>Org.igniterealtime.smack</groupId> <Artifactid>Smack-tcp</Artifactid> <version>4.1.1</version> </Dependency> <Dependency> <groupId>Org.igniterealtime.smack</groupId> <Artifactid>Smack-im</Artifactid> <version>4.1.1</version> </Dependency> <Dependency> <groupId>Org.igniterealtime.smack</groupId> <Artifactid>Smack-extensions</Artifactid> <version>4.1.1</version> </Dependency>
Example of a Java client sending a get message
Packagecom.openfire.client;Importjava.io.IOException;ImportJava.util.Scanner;Importorg.jivesoftware.smack.AbstractXMPPConnection;ImportOrg.jivesoftware.smack.StanzaListener;Importorg.jivesoftware.smack.XMPPException;ImportOrg.jivesoftware.smack.chat.Chat;ImportOrg.jivesoftware.smack.chat.ChatManager;ImportOrg.jivesoftware.smack.chat.ChatManagerListener;ImportOrg.jivesoftware.smack.chat.ChatMessageListener;ImportOrg.jivesoftware.smack.ConnectionConfiguration.SecurityMode;Importorg.jivesoftware.smack.SmackException;Importorg.jivesoftware.smack.SmackException.NotConnectedException;ImportOrg.jivesoftware.smack.filter.StanzaFilter;ImportOrg.jivesoftware.smack.packet.Message;ImportOrg.jivesoftware.smack.packet.Stanza;Importorg.jivesoftware.smack.tcp.XMPPTCPConnection;Importorg.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;/*** Hello world! **/ Public classAppextendsThread {voidsay () {}; Public Static voidMain (string[] args)throwssmackexception, IOException, Xmppexception, interruptedexception {//configuration of the connectionXmpptcpconnectionconfiguration.builder Builder =Xmpptcpconnectionconfiguration.builder (); Builder.setusernameandpassword ("Admin", "123456"); Builder.setservicename ("Ww110"); OpenFire server name, login management background can view Builder.sethost ("192.168.0.110"); Builder.setport (5222); //do not add this line error, because there is no certificateBuilder.setsecuritymode (securitymode.disabled); //saslauthentication.supportsaslmechanism ("PLAIN", 0);Builder.setdebuggerenabled (true); Xmpptcpconnectionconfiguration Config=Builder.build (); //establish a connection and log inAbstractxmppconnection C =Newxmpptcpconnection (config); C.addpacketsendinglistener (NewStanzalistener () {@Override Public voidProcesspacket (Stanza St)throwsnotconnectedexception {System.out.println ("In Stanzalistener:" +St.getfrom ()); } }, NewStanzafilter () {@Override Public BooleanAccept (Stanza St) {System.out.println ("In Stanzafilter:" +St.getfrom ()); return false; } }); C.connect (); C.login (); Chatmanager Chatmanager=chatmanager.getinstancefor (c); Chatmanager.addchatlistener (NewChatmanagerlistener () {@Override Public voidChatcreated (Chat cc,BooleanBB) { //trigger a listener function when receiving messages from each otherCc.addmessagelistener (NewChatmessagelistener () {@Override Public voidProcessMessage (Chat cc, Message mm) {System.out.println ("APP2 received message:" + CC +mm.getbody ()); } }); } }); while(true) {Sleep (2000);
Send messages to New1 users every 2 seconds chat chat= Chatmanager.createchat ("New1"); Chat.getthreadid (); Message msg=NewMessage (); Msg.setbody ("kkkkkkkkkkkkkkkkkkkkk33333333333333333333333333333333333"); Chat.sendmessage (msg); } }}
Summarize:
OpenFire only studied this, and for the time being it was written.
OpenFire Introduction to Java Applications