Debian Codegraph @

client.go

raw
1 package muxado
2
3 import (
4 "crypto/tls"
5 "github.com/inconshreveable/muxado/proto"
6 "github.com/inconshreveable/muxado/proto/ext"
7 "net"
8 )
9
10 // Client returns a new muxado client-side connection using conn as the transport.
11 func Client(conn net.Conn) Session {
12 return &sessionAdaptor{proto.NewSession(conn, proto.NewStream, true, []proto.Extension{ext.NewDefaultHeartbeat()})}
13 }
14
15 // Dial opens a new connection to the given network/address and then beings a muxado client session on it.
16 func Dial(network, addr string) (sess Session, err error) {
17 conn, err := net.Dial(network, addr)
18 if err != nil {
19 return
20 }
21 return Client(conn), nil
22 }
23
24 // DialTLS opens a new TLS encrytped connection with the givent configuration
25 // to the network/address and then beings a muxado client session on it.
26 func DialTLS(network, addr string, tlsConfig *tls.Config) (sess Session, err error) {
27 conn, err := tls.Dial(network, addr, tlsConfig)
28 if err != nil {
29 return
30 }
31 return Client(conn), nil
32 }