How to make a chat app


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]@[]/[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=''

valid xml stazas contains presence message and iq


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

<presence type=’unavailable’>

message stanza

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

children node:

<message to=’’ type=’normal’>
<body>Hey, do you have any WMD?</body>

<message to=’’
<subject>Re: WMD?</subject>
<body>Nop, I don’t have any.</body>


Client requests server-side filter-list:

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

<iq from=’user@server.tld’ type=’result’ id=’request1’>
<query xmlns=’jabber:iq:filter’>

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


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