func Dial(addr string, id string, cleanSession bool, auth *ConnectAuth, will *Message) (*Client, error) {

	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	stream := NewStream(conn, time.Second*30)

	client := &Client{
		id: id,
		//	CleanSession: cleanSession,
		stream: stream,

		pending:    make(map[int]Packet, 16),
		MaxPending: MaxPending,
	}

	// send MQTT Connect packet
	client.Send(Connect("MQTT", byte(0x04), cleanSession, 5000, id, will, auth))

	pkt, err := stream.ReadPacket()
	if err != nil {
		return client, err
	}

	if connAck, ok := pkt.(*ConnAckPacket); ok {
		switch connAck.Code {
		case CodeAccepted: // Yeah :)
			return client, nil

		default:
			return client, fmt.Errorf("connect error: %s", connAck.Code)
		}
	} else {

		return client, errUnexpectedPacket(pkt.Header().PacketType)
	}
}
// Dial connects to a remote MQTT server.
Dial connects to a remote MQTT server.
// Dial connects to a remote MQTT server .
func Dial(addr string, id string, cleanSession bool, auth *ConnectAuth, will *Message) (*Client, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}
	stream := NewStream(conn, time.Second*30)
	client := &Client{
		id: id,
		stream: stream,
		pending:    make(map[int]Packet, 16),
		MaxPending: MaxPending,
	}
	client.Send(Connect("MQTT", byte(0x04), cleanSession, 5000, id, will, auth))
	pkt, err := stream.ReadPacket()
	if err != nil {
		return client, err
	}
	if connAck, ok := pkt.(*ConnAckPacket); ok {
		switch connAck.Code {
		case CodeAccepted: 
			return client, nil
		default:
			return client, fmt.Errorf("connect error: %s", connAck.Code)
		}
	} else {
		return client, errUnexpectedPacket(pkt.Header().PacketType)
	}
}
func Dial ( addr string , id string , cleanSession bool , auth * ConnectAuth , will * Message ) ( * Client , error ) { conn , err := net . Dial ( " " , addr ) if err != nil { return nil , err } stream := NewStream ( conn , time . Second * 30 ) client := & Client { id : id , stream : stream , pending : make ( map [ int ] Packet , 16 ) , MaxPending : MaxPending , } client . Send ( Connect ( " " , byte ( 0x04 ) , cleanSession , 5000 , id , will , auth ) ) pkt , err := stream . ReadPacket ( ) if err != nil { return client , err } if connAck , ok := pkt . ( * ConnAckPacket ) ; ok { switch connAck . Code { case CodeAccepted : return client , nil default : return client , fmt . Errorf ( " " , connAck . Code ) } } else { return client , errUnexpectedPacket ( pkt . Header ( ) . PacketType ) } }
Dial connects to a remote MQTT server.
Dial connects to a remote MQTT server .
//	CleanSession: cleanSession, // send MQTT Connect packet // Yeah :)