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)
die2 := make(chan bool, 1)
go func() {
io.Copy(stream, inConn)
die1 <- true
}()
go func() {
io.Copy(inConn, stream) 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
} }
go func() {
var ID, clientLocalAddr, serverID string var ID, clientLocalAddr, serverID string
err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID) err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID)
if err != nil { if err != nil {
log.Printf("read connection signal err: %s, retrying...", err) log.Printf("read stream signal err: %s", err)
break stream.Close()
return
} }
log.Printf("signal revecived:%s %s %s", serverID, ID, clientLocalAddr) log.Printf("signal revecived:%s %s %s", serverID, ID, clientLocalAddr)
protocol := clientLocalAddr[:3] protocol := clientLocalAddr[:3]
localAddr := clientLocalAddr[4:] localAddr := clientLocalAddr[4:]
if protocol == "udp" { if protocol == "udp" {
go s.ServeUDP(stream, localAddr, ID) s.ServeUDP(stream, localAddr, ID)
} else { } else {
go s.ServeConn(stream, localAddr, ID) s.ServeConn(stream, localAddr, ID)
} }
}()
} }
} }