⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x3837.htm

📁 Its a xmpp protocol book
💻 HTM
📖 第 1 页 / 共 2 页
字号:
>client (to server)</I
>
conversation.</P
><P
>This namespace specification is required because a client connection is
just one type of
connection that can be made with a Jabber server, and different connections
carry conversations with different content.
<A
HREF="x3625.htm#JABTDG-CH-5-TAB-1"
>Table 5-1</A
> lists the
conversation namespaces currently defined in the Jabber protocol.</P
></DD
></DL
></DIV
><DIV
CLASS="TABLE"
><A
NAME="JABTDG-CH-5-TAB-2"
></A
><P
><B
>Table 5-2. Conversation Namespaces</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Namespace</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>jabber:client</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>This is the namespace that qualifies a connection between a Jabber client
and a Jabber server.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>jabber:server</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>This namespace qualifies a connection between two Jabber servers.
<I
CLASS="EMPHASIS"
>Dialback</I
> (host verification mechanism) conversations
take place within the <TT
CLASS="LITERAL"
>jabber:server</TT
>
namespace.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>jabber:component:accept</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>When an external program connects to a Jabber server via a TCP sockets
connection, this namespace is used to qualify the pair of XML
documents exchanged over the connection.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="LITERAL"
>jabber:component:exec</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>When an external program connects to a Jabber server via a STDIO
connection, this namespace is used to qualify the pair of XML
documents exchanged over such the connection.

<A
NAME="STDIO"
HREF="#FTN.STDIO"
>[a]</A
>&#13;</TD
></TR
></TBODY
><TR
><TD
COLSPAN="2"
>Notes:<BR><A
NAME="FTN.STDIO"
>a. </A
>For more details on external program connections to Jabber, see Chapter 4.<BR></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5-SECT-5.3.3"
>The Response</A
></H2
><P
>To complete our initial look at XML streams in a Jabber client-server
conversation, let's have a look at what the Jabber server might send
in response to the opening tag from the client:</P
><P
><PRE
CLASS="SCREEN"
>&#60;stream:stream
    xmlns:stream='http://etherx.jabber.org/streams'
    id='3AFD6862'
    xmlns='jabber:client'
    from='jabber.org'&#62;</PRE
></P
><P
>There are a couple of differences between this opening tag from the server
and the opening tag from the client. That is, above and beyond the fact that
this response's opening tag is for a document that is going to be streamed
along the socket in the opposite direction to that of document to which the
the request's opening tag belongs. The first difference is that there's a
<TT
CLASS="LITERAL"
>from</TT
> attribute instead of a <TT
CLASS="LITERAL"
>to</TT
>
attribute. The second difference is that there's an extra
attribute&mdash;<TT
CLASS="LITERAL"
>id</TT
>. Let's look at these in turn.</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>The <TT
CLASS="LITERAL"
>from</TT
> attribute</DT
><DD
><P
><TT
CLASS="LITERAL"
>from="jabber.org"</TT
></P
><P
>The <TT
CLASS="LITERAL"
>from</TT
> attribute is fairly straightforward;
it normally serves to confirm to the client that the requested
logical host is available. If the host is available, the value of the
<TT
CLASS="LITERAL"
>from</TT
> attribute from the server will match
the value of the <TT
CLASS="LITERAL"
>to</TT
> attribute from the
client. However, in some circumstances the value can be different.
The value sent in the <TT
CLASS="LITERAL"
>from</TT
> attribute is a
<I
CLASS="EMPHASIS"
>redirection</I
>, or <I
CLASS="EMPHASIS"
>respecification</I
>,
of the logical host by which the Jabber server (or more specifically the
JSM component within the Jabber server) is actually known.</P
><P
>Logical host aliases can be defined in the Jabber server's configuration
to &ldquo;convert&rdquo; a hostname specified in the incoming <TT
CLASS="LITERAL"
>to</TT
>
attribute. The <TT
CLASS="LITERAL"
>&#60;alias/&#62;</TT
> tag, which is used to define
these logical host aliases, is described in <A
HREF="x1740.htm#JABTDG-CH-4-SECT-4.3.3"
>the section called <I
>Component Instance: <I
CLASS="EMPHASIS"
>c2s</I
></I
> in Chapter 4</A
>.
But how are these hostname conversions used? Here's an example&hellip;</P
><P
>Let's say that you're running a Jabber server on an
internal network that doesn't have an available DNS server. The host
where the Jabber server runs is called <TT
CLASS="FILENAME"
>apollo</TT
>,
and its IP address is <TT
CLASS="LITERAL"
>192.168.1.4</TT
>. Some people will connect to the host
via the hostname because they have it defined in a local
<TT
CLASS="FILENAME"
>/etc/hosts</TT
> file; others will connect via the IP address.
Normally, the hostname (or IP address) specified in the connection
parameters given to a Jabber client will be:</P
><P
></P
><UL
><LI
><P
>Used to build the socket connection to the Jabber server.</P
></LI
><LI
><P
>Specified in the <TT
CLASS="LITERAL"
>to</TT
> attribute in the opening XML stream to
specify the logical host.</P
></LI
></UL
><P
>If the JSM section of the Jabber server is defined to have a hostname
of <TT
CLASS="FILENAME"
>apollo</TT
>:</P
><P
><PRE
CLASS="SCREEN"
>&#60;host&#62;&#60;jabberd:cmdline flag='h'&#62;apollo&#60;/jabberd:cmdline&#62;&#60;/host&#62;</PRE
></P
><P
>then we need to make sure that the Jabber client uses that name when
forming any JIDs for that Jabber server (e.g., the JID
<TT
CLASS="LITERAL"
>apollo</TT
> used as an addressee for an IQ browse
request). Having this:</P
><P
><PRE
CLASS="SCREEN"
>&#60;alias to='apollo'&#62;192.168.1.4&#60;/alias&#62;</PRE
></P
><P
>in our <TT
CLASS="LITERAL"
>c2s</TT
> instance configuration would mean that
any incoming XML stream header with a value of <TT
CLASS="LITERAL"
>192.168.1.4</TT
> in the
<TT
CLASS="LITERAL"
>to</TT
> attribute:</P
><P
><PRE
CLASS="SCREEN"
>&#60;stream:stream
    to="192.168.1.4"
    xmlns="jabber:client"
    xmlns:stream="http://etherx.jabber.org/streams"&#62;</PRE
></P
><P
>would elicit the following response:</P
><P
><PRE
CLASS="SCREEN"
>&#60;stream:stream
    from='apollo'
    id='1830EF6A'
    xmlns='jabber:client'
    xmlns:stream='http://etherx.jabber.org/streams'&#62;</PRE
></P
><P
>which effectively says: &ldquo;<I
CLASS="EMPHASIS"
>Okay, you requested <TT
CLASS="LITERAL"
>192.168.0.4</TT
>, but
please use <TT
CLASS="LITERAL"
>apollo</TT
> instead</I
>.&rdquo; The client should use the value
<I
CLASS="EMPHASIS"
>confirmed</I
> in the <TT
CLASS="LITERAL"
>from</TT
> attribute when referring to
that Jabber server in all subsequent stream fragments.</P
><P
>Not specifying an <TT
CLASS="LITERAL"
>&#60;alias/&#62;</TT
> tag in this
example would result in problems for the client. Without any
way of checking and converting incoming hostnames, the
<TT
CLASS="LITERAL"
>c2s</TT
> component will by default simply transfer the
value from the <TT
CLASS="LITERAL"
>to</TT
> attribute to the
<TT
CLASS="LITERAL"
>from</TT
> attribute in its stream header reply.</P
><P
>Following this thread to its natural conclusion, it's worth pointing
out that if we have an <TT
CLASS="LITERAL"
>alias</TT
> specification like this:</P
><P
><PRE
CLASS="SCREEN"
>&#60;alias to='apollo'/&#62;</PRE
></P
><P
>then the value of the <TT
CLASS="LITERAL"
>from</TT
> attribute in the reply
will <I
CLASS="EMPHASIS"
>always</I
> be set to <TT
CLASS="FILENAME"
>apollo</TT
>
regardless of what's specified in the <TT
CLASS="LITERAL"
>to</TT
> attribute. This means that the <TT
CLASS="LITERAL"
>to</TT
> attribute could be left out
of the opening stream tag. Although this serves well to illustrate the
point, it is not good practise.</P
></DD
><DT
>The <TT
CLASS="LITERAL"
>id</TT
> attribute</DT
><DD
><P
><TT
CLASS="LITERAL"
>id='3AFD6862'</TT
></P
><P
>The <TT
CLASS="LITERAL"
>id</TT
> attribute is the ID of the XML stream, and
is used in the subsequent authorization steps, which are described
in <A
HREF="c6313.htm"
>Chapter 6</A
>. The value is a random
hexadecimal string generated by the server, and is not important per se.
What <I
CLASS="EMPHASIS"
>is</I
> important is that it's a value that is 
random, and shared between server and client. The server knows what it
is because it generated it, and the client knows what it is because the
server sends it in the opening tag of the response.</P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-5-SECT-5.3.4"
>The Simplest Jabber Client</A
></H2
><P
>Now that we know how a conversation with a Jabber server is started, 
let's try it ourselves. At a stretch, one could say that the simplest
Jabber client, just like the simplest HTTP client, or the simplest client
that has to interact with <I
CLASS="EMPHASIS"
>any</I
> server that employs a
<I
CLASS="EMPHASIS"
>text-based</I
> protocol over a socket connection, is
<B
CLASS="COMMAND"
>telnet</B
>.</P
><P
>Simply point <B
CLASS="COMMAND"
>telnet</B
> to Jabber server, specifying
port 5222, and send an opening tag. You will receive an opening tag, from
the server, in response:</P
><P
><PRE
CLASS="SCREEN"
>yak:~$ <TT
CLASS="USERINPUT"
><B
>telnet localhost 5222</B
></TT
>
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
<TT
CLASS="USERINPUT"
><B
>&#60;?xml version='1.0'?&#62;
&#60;stream:stream xmlns:stream='http://etherx.jabber.org/streams' to='yak' xmlns='jabber:client'&#62;</B
></TT
>
&#60;?xml version='1.0'?&#62;&#60;stream:stream xmlns:stream='http://etherx.jabber.org/streams' id='3AFD839E' xmlns='jabber:client' from='yak'&#62;</PRE
></P
><P
>(If you haven't got a Jabber server to experiment with, see
<A
HREF="c813.htm"
>Chapter 3</A
> on how to set one up.)</P
><P
>Using <B
CLASS="COMMAND"
>telnet</B
> is a great way to find out more about
the way the Jabber protocol works. Perhaps the next thing to do is 
try out the user registration and authentication steps described in
<A
HREF="c6313.htm"
>Chapter 6</A
>. But watch out&mdash;send some invalid XML
the server will close the connection on you!</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x3795.htm"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x4089.htm"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Resources and Priority</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c3612.htm"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>The Jabber Building Blocks</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -