Instant Messaging using Erlang and XMPP — Part 1

Aug 9, 2020

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 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

# 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

# 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,

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.

Gajim Version Screenshot

Gajim - Adding a Contact Screenshot
Gajim - Subscription Request Screenshot
Gajim - Chatting Screenshot

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

Gajim - XML Console Screenshot

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.

   erlang (8) , mongooseim (4) , ejabberd (4) , xmpp (4) , instant-messaging (4) , docker (2)