Modification level bump.
[stompngo.git] / cmd / sng_showsvr / main.go
blob6a794740df40abc4a822854176ccc49c33df8ab9
1 //
2 // Copyright © 2017-2018 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 package main
19 import (
20 "fmt"
21 "log"
22 "net"
23 "os"
25 sng "github.com/gmallard/stompngo"
26 "github.com/gmallard/stompngo/senv"
29 func main() {
31 //=========================================================================
32 // Use something like this a boilerplate for connect (Yes, a lot of work,
33 // network connects usually are.)
34 host, port := senv.HostAndPort()
35 hap := net.JoinHostPort(host, port)
36 n, err := net.Dial(sng.NetProtoTCP, hap)
37 log.Printf("Connect Host and Port: %s\n", hap)
38 log.Printf("Connect Login: %s\n", senv.Login())
39 log.Printf("Connect Passcode: %s\n", senv.Passcode())
40 if err != nil {
41 log.Fatalln("Net Connect error for:", hap, "error:", err)
44 connect_headers := sng.Headers{sng.HK_LOGIN, senv.Login(),
45 sng.HK_PASSCODE, senv.Passcode(),
46 sng.HK_VHOST, senv.Vhost(),
47 sng.HK_HEART_BEAT, senv.Heartbeats(),
48 sng.HK_ACCEPT_VERSION, senv.Protocol(),
51 stomp_conn, err := sng.Connect(n, connect_headers)
52 if err != nil {
53 log.Printf("STOMP Connect failed, error:%v\n", err)
54 if stomp_conn != nil {
55 log.Printf("Connect Response: %v\n", stomp_conn.ConnectResponse)
57 os.Exit(1)
60 //=========================================================================
61 // Use something like this as real application logic
62 fmt.Printf("Client CONNECT Headers:\n%v\n", connect_headers)
63 fmt.Printf("Broker CONNECTED Data:\n")
64 fmt.Printf("Server: %s\n",
65 stomp_conn.ConnectResponse.Headers.Value(sng.HK_SERVER))
66 fmt.Printf("Protocol: %s\n",
67 stomp_conn.ConnectResponse.Headers.Value(sng.HK_VERSION))
68 fmt.Printf("Heartbeats: %s\n",
69 stomp_conn.ConnectResponse.Headers.Value(sng.HK_HEART_BEAT))
70 fmt.Printf("Session: %s\n",
71 stomp_conn.ConnectResponse.Headers.Value(sng.HK_SESSION))
74 //=========================================================================
75 // Use something like this as boilerplate for disconnect (Clean disconnects
76 // are also a lot of work.)
77 err = stomp_conn.Disconnect(sng.Headers{})
78 if err != nil {
79 log.Fatalf("DISCONNECT Failed, error:%v\n", err)
81 err = n.Close()
82 if err != nil {
83 log.Fatalf("Net Close Error:%v\n", err)