本文整理匯總了Golang中github.com/hashicorp/yamux.Session.Open方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Open方法的具體用法?Golang Session.Open怎麽用?Golang Session.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/yamux.Session
的用法示例。
在下文中一共展示了Session.Open方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleCreateTunnel
func handleCreateTunnel(session *yamux.Session, port int) (url string, err error) {
// TODO: Attempt to bind to local port
addr := fmt.Sprintf("127.0.0.1:%v", port)
log.WithFields(logrus.Fields{
"server": addr,
}).Info("attempting to connect to server")
local, err := net.Dial("tcp", addr)
if err != nil {
return "", errors.New("Could not establish connection to host port.")
}
log.WithFields(logrus.Fields{
"server": addr,
}).Info("connected to server")
// Establish stream
stream, err := session.Open()
if err != nil {
return "", errors.New("Could not create stream.")
}
// TODO: send control message
log.WithFields(logrus.Fields{
"server": addr,
}).Info("sending TunnelRequest")
req := &msg.TunnelRequest{
Port: port,
}
if err := msg.WriteMsg(stream, req); err != nil {
return "", err
}
// TODO: wait for ack w/ url
log.WithFields(logrus.Fields{
"server": addr,
}).Info("waiting for TunnelReply")
var res msg.TunnelReply
if err := msg.ReadMsgInto(stream, &res); err != nil {
return "", err
}
log.WithFields(logrus.Fields{
"server": addr,
"port": port,
"uri": res.URI,
}).Info("received TunnelReply")
url = res.URI
// TODO: Update global state for later control messages
// TODO: launch goroutine to proxy data
go proxy.Proxy(stream, local)
return url, nil
}