no message

This commit is contained in:
arraykeys
2017-12-01 22:14:07 +08:00
parent 4b35219c27
commit 7e2e63137e
2 changed files with 31 additions and 16 deletions

View File

@ -131,8 +131,20 @@ func (s *MuxBridge) callback(inConn net.Conn, key string) {
continue continue
} }
log.Printf("server stream %s created", ID) log.Printf("server stream %s created", ID)
go io.Copy(stream, inConn) die1 := make(chan bool, 1)
io.Copy(inConn, stream) die2 := make(chan bool, 1)
go func() {
io.Copy(stream, inConn)
die1 <- true
}()
go func() {
io.Copy(inConn, stream)
die2 <- true
}()
select {
case <-die1:
case <-die2:
}
stream.Close() stream.Close()
inConn.Close() inConn.Close()
log.Printf("server stream %s released", ID) log.Printf("server stream %s released", ID)

View File

@ -74,20 +74,23 @@ func (s *MuxClient) Start(args interface{}) (err error) {
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
break break
} }
var ID, clientLocalAddr, serverID string go func() {
err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID) var ID, clientLocalAddr, serverID string
if err != nil { err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID)
log.Printf("read connection signal err: %s, retrying...", err) if err != nil {
break log.Printf("read stream signal err: %s", err)
} stream.Close()
log.Printf("signal revecived:%s %s %s", serverID, ID, clientLocalAddr) return
protocol := clientLocalAddr[:3] }
localAddr := clientLocalAddr[4:] log.Printf("signal revecived:%s %s %s", serverID, ID, clientLocalAddr)
if protocol == "udp" { protocol := clientLocalAddr[:3]
go s.ServeUDP(stream, localAddr, ID) localAddr := clientLocalAddr[4:]
} else { if protocol == "udp" {
go s.ServeConn(stream, localAddr, ID) s.ServeUDP(stream, localAddr, ID)
} } else {
s.ServeConn(stream, localAddr, ID)
}
}()
} }
} }