1
0
Fork 0

Unindent overview docs.

This commit is contained in:
Matt Goodall 2012-07-20 15:04:46 +01:00
parent 8bb5c81347
commit 541db6d37c
1 changed files with 38 additions and 38 deletions

View File

@ -1,54 +1,54 @@
/*
Package for implementing XMPP clients and components.
Package for implementing XMPP clients and components.
The package is built around the concept of an XML stream - a pair of XML
documents written to and read from a TCP connection. Top-level elements in
the document form the messages processed by either end of the connection.
The package is built around the concept of an XML stream - a pair of XML
documents written to and read from a TCP connection. Top-level elements in the
document form the messages processed by either end of the connection.
An XML stream is then configured for an XMPP conversation, as either a
client (chat, etc) or component (a sort of server plugin).
An XML stream is then configured for an XMPP conversation, as either a client
(chat, etc) or component (a sort of server plugin).
Create a client:
Create a client:
jid, err := xmpp.ParseJID("alice@wonderland.lit/some-resource")
addr, err := xmpp.HomeServerAddrs(jid)
stream, err := xmpp.NewStream(addr[0], nil)
X, err := xmpp.NewClientXMPP(stream, jid, "password", nil)
jid, err := xmpp.ParseJID("alice@wonderland.lit/some-resource")
addr, err := xmpp.HomeServerAddrs(jid)
stream, err := xmpp.NewStream(addr[0], nil)
X, err := xmpp.NewClientXMPP(stream, jid, "password", nil)
Create a component:
Create a component:
jid, err := xmpp.ParseJID("rabbithole.wonderland.lit")
stream, err := xmpp.NewStream("localhost:5347", nil)
X, err := xmpp.NewComponentXMPP(stream, jid, "secret")
jid, err := xmpp.ParseJID("rabbithole.wonderland.lit")
stream, err := xmpp.NewStream("localhost:5347", nil)
X, err := xmpp.NewComponentXMPP(stream, jid, "secret")
Outgoing XMPP stanzas are sent to the XMPP instance's Out channel, e.g. a
client typically announces its presence on the XMPP network as soon as it's
connected:
Outgoing XMPP stanzas are sent to the XMPP instance's Out channel, e.g. a
client typically announces its presence on the XMPP network as soon as it's
connected:
X.Out <- xmpp.Presence{}
X.Out <- xmpp.Presence{}
Incoming messages are handled by consuming the XMPP instance's In channel.
The channel is sent all XMPP stanzas as well as terminating error (io.EOF
for clean shutdown or any other error for something unexpected). The
channel is also closed after an error.
Incoming messages are handled by consuming the XMPP instance's In channel. The
channel is sent all XMPP stanzas as well as terminating error (io.EOF for clean
shutdown or any other error for something unexpected). The channel is also
closed after an error.
XMPP defines four types of stanza: <error/>, <iq/>, <message/> and
<presence/> represented by Error, Iq, Message (shown below) and Presence
structs respectively.
XMPP defines four types of stanza: <error/>, <iq/>, <message/> and <presence/>
represented by Error, Iq, Message (shown below) and Presence structs
respectively.
for i := range X.In {
switch v := i.(type) {
case error:
log.Printf("error : %v\n", v)
case *xmpp.Message:
log.Printf("msg : %s says %s\n", v.From, v.Body)
default:
log.Printf("%T : %v\n", v, v)
}
for i := range X.In {
switch v := i.(type) {
case error:
log.Printf("error : %v\n", v)
case *xmpp.Message:
log.Printf("msg : %s says %s\n", v.From, v.Body)
default:
log.Printf("%T : %v\n", v, v)
}
}
Note: A "bound" JID is negotatiated during XMPP setup and may be different
to the JID passed to the New(Client|Component)XMPP() call. Always
use the XMPP instance's JID attribute in any stanzas.
Note: A "bound" JID is negotatiated during XMPP setup and may be different to
the JID passed to the New(Client|Component)XMPP() call. Always use the XMPP
instance's JID attribute in any stanzas.
*/
package xmpp