~samwhited/xmpp

ref: b2f3a9a952493ffcf467eafa59803c27fa099e2d xmpp/ping/example_test.go -rw-r--r-- 672 bytes
b2f3a9a9Sam Whited xmpp: make SendElement safe for concurrent use 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2017 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package ping_test

import (
	"encoding/xml"
	"log"
	"os"

	"mellium.im/xmlstream"
	"mellium.im/xmpp/jid"
	"mellium.im/xmpp/ping"
)

func ExampleIQ() {
	j := jid.MustParse("feste@example.net/siJo4eeT")
	e := xml.NewEncoder(os.Stdout)
	e.Indent("", "\t")

	ping := ping.IQ(j)
	if _, err := xmlstream.Copy(e, ping); err != nil {
		log.Fatal(err)
	}
	if err := e.Flush(); err != nil {
		log.Fatal(err)
	}

	// Output:
	// <iq type="get" to="feste@example.net/siJo4eeT">
	//	<ping xmlns="urn:xmpp:ping"></ping>
	// </iq>
}