本文整理汇总了Golang中frp/utils/conn.Conn.GetRemoteAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.GetRemoteAddr方法的具体用法?Golang Conn.GetRemoteAddr怎么用?Golang Conn.GetRemoteAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frp/utils/conn.Conn
的用法示例。
在下文中一共展示了Conn.GetRemoteAddr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Start
// start listening for user conns
func (p *ProxyServer) Start(c *conn.Conn) (err error) {
p.CtlConn = c
p.Init()
if p.Type == "tcp" {
l, err := conn.Listen(p.BindAddr, p.ListenPort)
if err != nil {
return err
}
p.listeners = append(p.listeners, l)
} else if p.Type == "http" {
for _, domain := range p.CustomDomains {
l, err := VhostMuxer.Listen(domain)
if err != nil {
return err
}
p.listeners = append(p.listeners, l)
}
}
p.Lock()
p.Status = consts.Working
p.Unlock()
// start a goroutine for every listener to accept user connection
for _, listener := range p.listeners {
go func(l Listener) {
for {
// block
// if listener is closed, err returned
c, err := l.Accept()
if err != nil {
log.Info("ProxyName [%s], listener is closed", p.Name)
return
}
log.Debug("ProxyName [%s], get one new user conn [%s]", p.Name, c.GetRemoteAddr())
if p.Status != consts.Working {
log.Debug("ProxyName [%s] is not working, new user conn close", p.Name)
c.Close()
return
}
// start another goroutine for join two conns from frpc and user
go func() {
workConn, err := p.getWorkConn()
if err != nil {
return
}
userConn := c
// msg will transfer to another without modifying
// l means local, r means remote
log.Debug("Join two connections, (l[%s] r[%s]) (l[%s] r[%s])", workConn.GetLocalAddr(), workConn.GetRemoteAddr(),
userConn.GetLocalAddr(), userConn.GetRemoteAddr())
if p.UseEncryption {
go conn.JoinMore(userConn, workConn, p.AuthToken)
} else {
go conn.Join(userConn, workConn)
}
}()
}
}(listener)
}
return nil
}