-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (39 loc) · 791 Bytes
/
main.go
File metadata and controls
45 lines (39 loc) · 791 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func main() {
my := MyXMPP{
ServerAddess: "192.168.1.1:5222",
Name: "id@xmpp-host",
Password: "1234"
SSL: false, //if setting with default when you install jabberd2
}
my.Connect()
go func() {
for {
from, chat, err := my.GetMessage()
if err != nil {
log.Fatal(err)
}
fmt.Println(from, chat)
}
}()
for {
in := bufio.NewReader(os.Stdin)
line, err := in.ReadString('\n')
if err != nil {
continue
}
line = strings.TrimRight(line, "\n")
tokens := strings.SplitN(line, " ", 2)
fmt.Printf("input name=%s, msg=%s \n", tokens[0], tokens[1])
if len(tokens) == 2 {
my.SendMessage(tokens[0], tokens[1])
}
}
}