How to make a chat app

XMPP

tldr It is a IM protocol that use XML, it is decentialized, and XML itself contain rounting info, and it is the server that doing all the heavy work :P

first questin about a IM protocal is how you set a identity? and on a decentrialized architecure?[longwei]@[server.com]/[resource]

then it is server’s job to route the message to other xmpp server. the same way you make a call from tmobile to att. It is the server that doing the hard job.

message setup

  • create TCP connect
  • bidirection xml stream
  • TLS handshake
  • auth/resouce binding.
  • message/presence

XML stream are exchanged, and each one is a set of stanzas. it could be async based on event-loop.

example of connecting

<stream: stream to='jabber.org'
    xmlns='jabber:client'
    xmlns:stream=''http://foobar/stream
          version='1.0'>

valid xml stazas contains presence message and iq

presence

  1. type:”availabel”/”unavailabel”
  2. to: optinal
  3. from:
  4. show:”away”/”chat”/”dnd”/”xa”
  5. status: ““showering. . .”
send:
<presence type=’available’>
<status>showering...</status>
</presence>

received:
<presence type=’unavailable’>
from=’user@server.tld/resource’>
<status>Disconnected</status>
</presence>

message stanza

to: target JID, from: source JID type: normal/chat/groupchat

children node:

  <subject>
  <body>
  <thread>
  <x>
<message to=’saddam@jabber.gov.iq’ type=’normal’>
<subject>WMD?</subject>
<body>Hey, do you have any WMD?</body>
</message>

<message to=’gwb@whitehouse.gov’
from=’saddam@jabber.gov.iq/ak47’
type=’normal’>
<subject>Re: WMD?</subject>
<body>Nop, I don’t have any.</body>
</message>

iq

Client requests server-side filter-list:

<iq type=’get’ id=’request1’>
<query xmlns=’jabber:iq:filter’/>
</iq>

<iq from=’user@server.tld’ type=’result’ id=’request1’>
<query xmlns=’jabber:iq:filter’>
<rule>
<body>moin</body>
<reply>tachauch</reply>
<continue/>
</rule>
</query>
</iq>

multi-party and notification

like IRC but with room configuration, in-room voting, and various session control messages. notification is slim version of one-way group chat

Service discoery

enables you to find out which features are supported by another entity, as well as any additional entities that are associated with it

misc

roster: contact list

Peer-to-peer media sessions

defined in XEP-0166,negotiate and manage a media session with another entity. Such a session can be used for the purpose of voice chat, video chat, file transfer, and other real-time interactions.

Written on January 16, 2015