Skip to content

Commit

Permalink
连接bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
刘河 committed Nov 29, 2018
1 parent a32010f commit 86deb20
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 2 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
"io"
"log"
"net"
"sync"
Expand Down Expand Up @@ -107,8 +106,8 @@ func (s *TRPClient) dealChan() error {
return err
}
//创建成功后io.copy
go io.Copy(server, c)
io.Copy(c, server)
go relay(server, c.conn)
relay(c.conn, server)
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
Expand Down Expand Up @@ -179,7 +178,7 @@ retry:
if _, err := link.WriteHost(s.tunnelTarget); err != nil {
goto retry
}
go io.Copy(link, c)
io.Copy(c, link.conn)
go relay(link.conn, c.conn)
relay(c.conn, link.conn)
return nil
}
1 change: 1 addition & 0 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (s *Tunnel) cliProcess(c *Conn) error {
s.verifyError(c)
return err
}
c.conn.(*net.TCPConn).SetReadDeadline(time.Time{})
//做一个判断 添加到对应的channel里面以供使用
flag, err := c.ReadFlag()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"encoding/binary"
"errors"
"fmt"
"io"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
Expand Down Expand Up @@ -146,3 +149,10 @@ func replaceHost(resp []byte) []byte {
}
return []byte(str)
}

func relay(in, out net.Conn) {
if _, err := io.Copy(in, out); err != nil {
log.Println("copy error:", err)
}
in.Close() //
}

0 comments on commit 86deb20

Please sign in to comment.