Ejemplo n.º 1
0
/*
	Open a network connection.
*/
func openConn(t *testing.T) (net.Conn, error) {
	h, p := senv.HostAndPort()
	hap := net.JoinHostPort(h, p)
	n, err := net.Dial(NetProtoTCP, hap)
	if err != nil {
		t.Fatalf("Unexpected net.Dial error: %v\n", err)
	}
	return n, err
}
Ejemplo n.º 2
0
// Common example connect logic
func CommonConnect(exampid, tag string, l *log.Logger) (net.Conn,
	*stompngo.Connection,
	error) {

	l.Printf("%stag:%s consess:%v common_connect_starts\n",
		exampid, tag, Lcs)

	// Set up the connection.
	h, p := senv.HostAndPort()
	hap := net.JoinHostPort(h, p)
	n, e := net.Dial("tcp", hap)
	if e != nil {
		return nil, nil, e
	}

	l.Printf("%stag:%s connsess:%s common_connect_host_and_port:%v\n",
		exampid, tag, Lcs,
		hap)

	// Create connect headers and connect to stompngo
	ch := ConnectHeaders()
	l.Printf("%stag:%s connsess:%s common_connect_headers headers:%v\n",
		exampid, tag, Lcs,
		ch)
	conn, e := stompngo.Connect(n, ch)
	if e != nil {
		return nil, conn, e
	}
	l.Printf("%stag:%s connsess:%s common_connect_complete host:%s port:%s vhost:%s protocol:%s server:%s\n",
		exampid, tag, conn.Session(),
		h, p, senv.Vhost(), conn.Protocol(), ServerIdent(conn))

	// Show connect response
	l.Printf("%stag:%s connsess:%s common_connect_response connresp:%v\n",
		exampid, tag, conn.Session(),
		conn.ConnectResponse)

	// Heartbeat Data
	l.Printf("%stag:%s connsess:%s common_connect_heart_beat_send hbsend:%d\n",
		exampid, tag, conn.Session(),
		conn.SendTickerInterval())
	l.Printf("%stag:%s connsess:%s common_connect_heart_beat_recv hbrecv:%d\n",
		exampid, tag, conn.Session(),
		conn.ReceiveTickerInterval())

	l.Printf("%stag:%s connsess:%s common_connect_local_addr:%s\n",
		exampid, tag, conn.Session(),
		n.LocalAddr().String())
	l.Printf("%stag:%s connsess:%s common_connect_remote_addr:%s\n",
		exampid, tag, conn.Session(),
		n.RemoteAddr().String())

	//
	return n, conn, nil
}
Ejemplo n.º 3
0
/*
	Host and port for Dial
*/
func hostAndPort() (string, string) {
	return senv.HostAndPort()
}
Ejemplo n.º 4
0
// Common example TLS connect logic
func CommonTLSConnect(exampid, tag string, l *log.Logger,
	c *tls.Config) (net.Conn, *stompngo.Connection, error) {

	l.Printf("%stag:%s consess:%s common_tls_connect_starts\n",
		exampid, tag, Lcs)

	// Set up the connection.
	h, p := senv.HostAndPort()
	hap := net.JoinHostPort(h, p)
	n, e := net.Dial("tcp", hap)
	if e != nil {
		return nil, nil, e
	}

	c.ServerName = h // SNI

	nc := tls.Client(n, c) // Returns: *tls.Conn : implements net.Conn
	e = nc.Handshake()
	if e != nil {
		if e.Error() == "EOF" {
			l.Printf("%stag:%s consess:%s common_tls_handshake_EOF_Is_the_broker_port_TLS_enabled? port:%s\n",
				exampid, tag, Lcs,
				p)
		}
		l.Fatalf("%stag:%s consess:%s common_tls_handshake_failed error:%v\n",
			exampid, tag, Lcs,
			e.Error())
	}
	l.Printf("%stag:%s consess:%s common_tls_handshake_complete\n",
		exampid, tag, Lcs)

	l.Printf("%stag:%s connsess:%s common_tls_connect_host_and_port:%v\n",
		exampid, tag, Lcs,
		hap)

	// Create connect headers and connect to stompngo
	ch := ConnectHeaders()
	l.Printf("%stag:%s connsess:%s common_tls_connect_headers headers:%v\n",
		exampid, tag, Lcs,
		ch)
	conn, e := stompngo.Connect(nc, ch)
	if e != nil {
		return nil, nil, e
	}
	l.Printf("%stag:%s connsess:%s common_tls_connect_complete host:%s vhost:%s protocol:%s server:%s\n",
		exampid, tag, conn.Session(),
		h, senv.Vhost(), conn.Protocol(), ServerIdent(conn))

	// Show connect response
	l.Printf("%stag:%s connsess:%s common_tls_connect_response connresp:%v\n",
		exampid, tag, conn.Session(),
		conn.ConnectResponse)

	// Show heartbeat data (if heart beats are being used)
	if senv.Heartbeats() != "" {
		l.Printf("%stag:%s connsess:%s common_tls_connect_heart_beat_send hbsend:%v\n",
			exampid, tag, conn.Session(),
			conn.SendTickerInterval())
		l.Printf("%stag:%s connsess:%s common_tls_connect_heart_beat_recv hbrecv:%v\n",
			exampid, tag, conn.Session(),
			conn.ReceiveTickerInterval())
	}

	l.Printf("%stag:%s connsess:%s common_tls_connect_local_addr:%s\n",
		exampid, tag, conn.Session(),
		n.LocalAddr().String())
	l.Printf("%stag:%s connsess:%s common_tls_connect_remote_addr:%s\n",
		exampid, tag, conn.Session(),
		n.RemoteAddr().String())

	//
	return nc, conn, nil
}