func Connect(server string) (*Client, net.Conn, error) {
	var sstr []serverString
	if server != "" {
		sstr = parseServerString(server)
	} else if serverRaw, ok := os.LookupEnv("PULSE_SERVER"); ok {
		sstr = parseServerString(serverRaw)
	} else {
		sstr = defaultServerStrings()
	}
	if len(sstr) == 0 {
		return nil, nil, errors.New("pulseaudio: no valid server")
	}
	c := &Client{}
	localname, err := os.Hostname()
	if err != nil {
		return nil, nil, err
	}
	var lastErr error
	for _, s := range sstr {
		if s.localname != "" && localname != s.localname {
			continue
		}
		conn, err := net.Dial(s.protocol, s.addr)
		if err != nil {
			lastErr = err
			continue
		}
		c.Open(conn)
		cookiePath := os.Getenv("HOME") + "/.config/pulse/cookie"
		if path, ok := os.LookupEnv("PULSE_COOKIE"); ok {
			cookiePath = path
		}
		cookie, err := ioutil.ReadFile(cookiePath)
		if err != nil {
			if !os.IsNotExist(err) {
				conn.Close()
				lastErr = err
				continue
			}
			cookie = make([]byte, 256)
		}
		var authReply AuthReply
		err = c.Request(
			&Auth{
				Version: c.Version(),
				Cookie:  cookie,
			}, &authReply)
		if err != nil {
			conn.Close()
			lastErr = err
			continue
		}
		c.SetVersion(authReply.Version)
		return c, conn, nil
	}
	return nil, nil, lastErr
}
Connect connects to the pulse server.

For the server string format see
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/ServerStrings/
If the server string is empty, the environment variable PULSE_SERVER will be used.
package proto
import (
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"os/user"
	"path"
	"runtime"
	"strings"
)