func SelectOneOf(protos []string, rwc io.ReadWriteCloser) (string, error) {
	if len(protos) == 0 {
		return "", ErrNoProtocols
	}
	switch err := SelectProtoOrFail(protos[0], rwc); err {
	case nil:
		return protos[0], nil
	case ErrNotSupported:  
	default:
		return "", err
	}
	return selectProtosOrFail(protos[1:], rwc)
}
SelectOneOf will perform handshakes with the protocols on the given slice
until it finds one which is supported by the muxer.
package multistream
import (
	"bytes"
	"crypto/rand"
	"encoding/binary"
	"errors"
	"io"
	"strconv"
	"strings"
)
var ErrNotSupported = errors.New("protocol not supported")
var ErrNoProtocols = errors.New("no protocols specified")
const (
	tieBreakerPrefix = "select:"
	initiator        = "initiator"
	responder        = "responder"
)
func SelectProtoOrFail(proto string, rwc io.ReadWriteCloser) error {
	errCh := make(chan error, 1)
	go func() {
		var buf bytes.Buffer
		if err := delitmWriteAll(&buf, []byte(ProtocolID), []byte(proto)); err != nil {
			errCh <- err
			return
		}
		_, err := io.Copy(rwc, &buf)
		errCh <- err
	}()
	err1 := readMultistreamHeader(rwc)
	err2 := readProto(proto, rwc)
	if werr := <-errCh; werr != nil {
		return werr
	}
	if err1 != nil {
		return err1
	}
	if err2 != nil {
		return err2
	}
	return nil
}