The protocol is not coupled to any network architecture, but it’s generally used in client-server architecture. An XMPP server can communicate with its clients (recommended port: 5222) or with other XMPP servers (recommended port: 5269) over a TCP connection.
An example network architecture could be like
The gateway is necessary to translate the messages between a non-XMPP server and an XMPP server.
All XMPP messaging happens in the form of Streams and Stanzas. Stream is the container for all messages sent from one entity to the other. A stream is initiated with a <stream> tag and is destroyed with a </stream> tag. Multiple XML elements can be sent over the connection before the stream is closed.
These streams are unidirectional i.e. if a client initiates a stream with the server to send a request; the server initiates a new response stream on the same TCP connection. Unlike the client-server communication, the server-server communication requires two separate TCP connections for exchange of XML elements over streams.
Stanza is one atomic unit of information that can be sent from one entity to another over a stream. It is a structured XML element. Three types of stanzas are defined in the XMPP standards:
message: used for instant messaging
presence: used for presence related messaging
iq: used in request-response services for querying information from entities.
The client-server (or server-server) communication can be thought of as two open-ended XML documents. The stream just wraps all the stanzas sent in a session from one entity to the other.
A stream with different stanzas:
Watch out for more on XMPP..