2013년 4월 25일 목요일

XMPP, Smack, Openfire

이전 블로그에서 이전 함 (원본 글 2013/04/25 작성)

  [Extensible Messaging and Presence Protocol (XMPP)]

 XMPP Intro


- XMPP is a open protocol for XML-based communication over the Internet
- The protocol was originally named Jabber.
    It was developed by the Jabber open-source community in 1999
   for near real-time, instant messaging (IM), presence information, and contact list maintenance
- XMPP has similarities to other application-layer protocols like SMTP.


- Address in XMPP
[ node "@" ] domain [ "/" resource ]
DavidBowman@discovery.nasa.guv 
DavidBowman@discovery.nasa.guv/terminal
DavidBowman@discovery.nasa.guv/eva_pod1

- The XMPP protocol
XMPP is a relatively simple protocol that occurs over TCP sockets using XML messages. Asynchronous communication occurs within XML streams and with XML stanzas.

- Pros
: Decentralization
   . Similar email 
   . No center master server
: Open standards
   . Based  RFC 6120 and RFC 6121)
   . No royalties are required
: History
   . XMPP technologies have been in use since 1999. 
   . Multiple implementations of the XMPP standards exist for clients, servers, components, and code libraries
: Security
   . Strong security (via SASL[Simple Authentication and Security Layer] and TLS[Transport Layer Security]) has been built into the core XMPP specifications.
: Flexibility
   . Custom functionality can be built on top of XMPP
   . XMPP applications beyond IM include group chat, network management, content syndication, collaboration tools, file sharing, gaming, remote systems control and monitoring, geolocation, middleware and cloud computing, VoIP and Identity services.

Cons
: In-band binary data transfer is inefficient
   . Binary data must be first base64 encoded before the transmission in-band.
Use out-of-band for the binary transfer (Jingle XMPP Extension Protocol)


  [Smack - XMPP based client library]

Smack API 3.2.2
Smack is an Open Source XMPP (Jabber) client library for instant messaging and presence. A pure Java library, it can be embedded into your applications to create anything from a full XMPP client to simple XMPP integrations such as sending notification messages and presence-enabling devices.



Smack Key Advantages
  • Extremely simple to use, yet powerful API. Sending a text message to a user can be accomplished in only a few lines of code:
    Connection connection = new XMPPConnection("jabber.org");
    connection.connect();
    connection.login("mtucker", "password");
    Chat chat = connection.getChatManager().createChat("jsmith@jivesoftware.com", new MessageListener() {
    
        public void processMessage(Chat chat, Message message) {
            System.out.println("Received message: " + message);
        }
    });
    chat.sendMessage("Howdy!");
    
  • Doesn't force you to code at the packet level, as other libraries do. Smack provides intelligent higher level constructs such as the Chat and Roster classes, which let you program more efficiently.
  • Does not require that you're familiar with the XMPP XML format, or even that you're familiar with XML.
  • Provides easy machine to machine communication. Smack lets you set any number of properties on each message, including properties that are Java objects.
  • Open Source under the Apache License, which means you can incorporate Smack into your commercial or non-commercial applications.



JAR Files and Requirements
Smack is meant to be easily embedded into any existing JDK 1.5 or later Java application. It has no external dependencies (except for the Jingle voice chat functionality) and is optimized to be as small as possible. The library ships as several JAR files to provide more flexibility over which features applications require:
  • smack.jar -- provides core XMPP functionality and is the only required library. All XMPP features that are part of the XMPP RFCs are included.
  • smackx.jar -- support for many of the the extensions (XEPs) defined by the XMPP Standards Foundation, including multi-user chat, file transfer, user search, etc. The extensions are documented in the extensions manual.
  • smackx-debug.jar -- an enhanced GUI debugger for protocol traffic. It will automatically be used when found in the classpath and when debugging is enabled.



Current Extensions

NameXEP #Description
Private DataXEP-0049Manages private data.
XHTML MessagesXEP-0071Allows send and receiving formatted messages using XHTML.
Message EventsJEP-0022Requests and responds to message events.
Data FormsJEP-0004Allows to gather data using Forms.
Multi User ChatJEP-0045Allows configuration of, participation in, and administration of individual text-based conference rooms.
Roster Item ExchangeXEP-0093Allows roster data to be shared between users.
Time ExchangeXEP-0090Allows local time information to be shared between users.
Group Chat InvitationsN/ASend invitations to other users to join a group chat room.
Service DiscoveryXEP-0030Allows to discover services in XMPP entities.
File TransferXEP-0096Transfer files between two users over XMPP.
PubSubXEP-0060Generic publish and subscribe functionality.




Chat
A chat creates a new thread of messages (using a thread ID) between two users. The following code snippet demonstrates how to create a new Chat with a user and then send them a text message:

// Assume we've created a Connection name "connection".
ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("jsmith@jivesoftware.com", new MessageListener() {
    public void processMessage(Chat chat, Message message) {
        System.out.println("Received message: " + message);
    }
});

try {
    newChat.sendMessage("Howdy!");
}
catch (XMPPException e) {
    System.out.println("Error Delivering block");
}



Using the API
All major objects have property support, such as Message objects. The following code demonstrates how to set properties:
Message message = chat.createMessage();
// Add a Color object as a property.
message.setProperty("favoriteColor", new Color(0, 0, 255));
// Add an int as a property.
message.setProperty("favoriteNumber", 4);
chat.sendMessage(message);
Getting those same properties would use the following code:
Message message = chat.nextMessage();
// Get a Color object property.
Color favoriteColor = (Color)message.getProperty("favoriteColor");
// Get an int property. Note that properties are always returned as
// Objects, so we must cast the value to an Integer, then convert
// it to an int.
int favoriteNumber = ((Integer)message.getProperty("favoriteNumber")).intValue();



Multi User Chat
Allows configuration of, participation in, and administration of individual text-based conference rooms.





 [Openfire - XMPP based server]

Openfire 3.8.1

Openfire is a real time collaboration (RTC) server licensed under the Open Source Apache License. It uses the only widely adopted open protocol for instant messaging, XMPP (also called Jabber). Openfire is incredibly easy to setup and administer, but offers rock-solid security and performance.

Installation

    Windows
    Run the Openfire installer. The application will be installed to c:\Program Files\Openfire by default.
    Linux/Unix
    Choose either the RPM or tar.gz build. If using the RPM, run it using your package manager to install Openfire to /opt/openfire:
    rpm -ivh openfire_3_0_0.rpm

    If using the .tar.gz, extract the archive to /opt or /usr/bin:
    tar -xzvf openfire_3_0_0.tar.gz
    mv openfire /opt

    Note: the .tar.gz build does not contain a bundled Java runtime (JRE). Therefore, you must have JDK or JRE 1.5.0 (Java 5) or later installed on your system. You can check your java version by typing "java -version" at the command line and (if necessary) upgrade your Java installation by visiting http://java.sun.com.

Running Openfire in Linux/Unix

If you are running on a Red Hat or Red Hat like system (CentOS, Fedora, etc), we recommend using the RPM as it contains some custom handling of the standard Red Hat like environment. Assuming that you have used the RPM, you can start and stop Openfire using the /etc/init.d/openfire script.
# /etc/init.d/openfire
Usage /etc/init.d/openfire {start|stop|restart|status|condrestart|reload}
# /etc/init.d/openfire start
Starting openfire:
If you are running on a different Linux/Unix varient, and/or you have used the .tar.gz 'installer', you can start and stop Openfire using the bin/openfire script in your Openfire installation:
# ./openfire
Usage: ./openfire {start|stop}
# ./openfire start
Starting openfire
If you would like to install Openfire as a service, two scripts are provided in the bin/extra directory:
  • redhat-postinstall.sh -- automatically installs Openfire as a service on Red Hat. It does so by creating a "jive" user and then copying the openfired script to your init.d directory. This script must be run as root. Please see the comments in the script for additional information.
  • openfired -- script to run Openfire as a service. You must manually configure this script. See the comments in the script for additional details.
 * admin console :  http://127.0.0.1:9090 

Basic IM Protocol Suite Support

The basic suite includes full support of the XMPP RFC's as well as the most common extensions. The table below details the level of support for the requirements set by XEP-0073: Basic IM Protocol Suite.
SpecificationSupported
RFC 3920: XMPP CoreYes
RFC 3921: XMPP IMYes
XEP-0030: Service DiscoveryYes
XEP-0077: In-Band RegistrationYes
XEP-0078: Non-SASL AuthenticationYes
XEP-0086: Error Condition MappingsYes

Intermediate IM Protocol Suite Support

The intermediate suite includes the full basic suite as well as more advanced features in common use by XMPP clients. The table below details the level of support for the requirements set byXEP-0117: Intermediate IM Protocol Suite.
SpecificationSupported
XEP-0073: Basic IM Protocol SuiteYes
XEP-0004: Data FormsYes
XEP-0020: Feature NegotiationNo
XEP-0045: Multi-User ChatYes
XEP-0047: In-Band BytestreamsYes
XEP-0065: SOCKS5 BytestreamsYes
XEP-0071: XHTML-IMYes [1]
XEP-0096: File TransferYes
XEP-0115: Entity CapabilitiesYes


  


[Spark - XMPP based client application]

Spark 2.6.3

Spark is an Open Source, cross-platform IM client optimized for businesses and organizations. It features built-in support for group chat, telephony integration, and strong security. It also offers a great end-user experience with features like in-line spell checking, group chat room bookmarks, and tabbed conversations.
Combined with the Openfire server, Spark is the easiest and best alternative to using un-secure public IM networks. 

댓글 없음:

댓글 쓰기