Instant Messaging
It’s a type of real-time text transmission over the internet and if you want detailed description of what it is please look it up here
Underlying Basics
There are a couple of things, we need to understand about real-time technologies:
- The underlying protocol is not HTTP/HTTPS, but raw TCP with TLS which is equivalent to HTTPS per se
- also there is a web socket which has been recently gaining popularity in the recent years
The fore mentioned protocols heavily rely on keeping the connection to the servers alive until the user forcefully disconnects, whereas the HTTP ones are open and close for every request strategy and not suitable when you want to hit real-time messaging.
XMPP — short and sweet
Extensible Messaging and Presence Protocol(XMPP) is a protocol which defines how the text transmission should happen over the wire, and it is lightweight compared to the traditional HTTP.
A detailed component of XMPP are here .
Note: It’s utmost important to understand what is XMPP and how it works to understand the servers that use XMPP
XMPP and Erlang — Why?
Erlang as we all know is fault-tolerant, scalable and can be easily decentralized by the right approach. The XMPP can be implemented in any language and already there are plenty of open-source projects using XMPP with other languages. This article will be mainly about Erlang based XMPP servers such as Ejabberd and MongooseIM.
Thanks to the contributors of those projects that made the Chat industry a huge market for many ventures.
For more XMPP servers, please look here
Getting Started
Installation for Test Drive
- Clone from git and use make to install either Ejabberd or MongooseIM.
- MongooseIM - install file can be downloaded from Erlang Solutions website
- Ejabberd has direct distribution through apt (apt install ejabberd)
- docker (Convenient and best approach)
# For Ejabberd
docker run --name ejabberd -d -p 5222:5222 ejabberd/ecs
# For MongooseIM
docker run -d -t -h mongooseim-1 --name mongooseim-1 -p 5222:5222 mongooseim/mongooseim:latest
Trying out our chat server
- Pick your favorite IM client from this page .
- To start chatting, you will need an account registered with our local server. The registration process is known as - In-Band Registration .
- For MongooseIM, the registration is done using the following commands
mongooseimctl register {HOST} {PASSWORD}
andmongooseimctl register_identified {USERNAME} {HOST} {PASSWORD}
# Registering using random username
$ mongooseimctl register localhost testpassword
User 1596-978064-173548-9A7D4C0FBABEEF51@localhost successfully registered
# Registering using username and password
$ mongooseimctl register_identified testuser localhost testpassword
User testuser@localhost successfully registered
Now, you might be wondering why can’t the user register directly? Indeed, the users can register themselves,
- if the in-band registration is enabled in the server
- It is disabled by default to prevent SPAM
- most services use XMPP as an add-on in their service, which also means the registration has already been carried out
- we don’t want to have second-time registration separately
- We can indirectly register the user using our service to communicate with our XMPP server
We will get in-depth about configuring our XMPP server later in the series of posts
Gajim — The chosen one
I have chosen Gajim as my demo chat client.
- Login to your accounts using the registered username, host and password
(also known as JabberID, which is of the form ({username}@{host}/{resource}))
- After logging in, add the other account as contact using
right-click on account name > Add Contact > Fill details > Add
- Now, the other user will receive a subscription request, you will need to
Authorize
it to be able to chat with the user
- Double-click on the username to start chatting and have fun for a while, before we go a bit deep.
Why all of this?
Gajim has a nice feature for introspection on the communication between the Chat Client and Chat Server.
To access it: Click on the Accounts > {Account Name} > Advanced > XML Console
You can see all the nice XML stanzas going in and out!
Wrapping up the part one with this tip! Stay tuned for more detailed posts about how to configure, deploy or develop an XMPP server.