utils/conn: support ipv6, fix #62

This commit is contained in:
fatedier 2016-08-12 00:32:33 +08:00
parent b4a577b0d7
commit 5d9300c1e9
4 changed files with 11 additions and 6 deletions

View File

@ -1,15 +1,13 @@
export PATH := $(GOPATH)/bin:$(PATH) export PATH := $(GOPATH)/bin:$(PATH)
export GO15VENDOREXPERIMENT := 1 export GO15VENDOREXPERIMENT := 1
all: fmt dep build all: fmt build
build: frps frpc build_test build: frps frpc build_test
build_test: echo_server http_server build_test: echo_server http_server
dep: statik assets:
statik:
go get -d github.com/rakyll/statik go get -d github.com/rakyll/statik
@go install github.com/rakyll/statik @go install github.com/rakyll/statik
@rm -rf ./src/assets/statik @rm -rf ./src/assets/statik

View File

@ -1,5 +1,7 @@
# [common] is integral section # [common] is integral section
[common] [common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
server_addr = 0.0.0.0 server_addr = 0.0.0.0
server_port = 7000 server_port = 7000
# console or real logFile path like ./frpc.log # console or real logFile path like ./frpc.log

View File

@ -1,5 +1,7 @@
# [common] is integral section # [common] is integral section
[common] [common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
bind_addr = 0.0.0.0 bind_addr = 0.0.0.0
bind_port = 7000 bind_port = 7000
# if you want to support virtual host, you must set the http port for listening (optional) # if you want to support virtual host, you must set the http port for listening (optional)

View File

@ -32,7 +32,10 @@ type Listener struct {
} }
func Listen(bindAddr string, bindPort int64) (l *Listener, err error) { func Listen(bindAddr string, bindPort int64) (l *Listener, err error) {
tcpAddr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", bindAddr, bindPort)) tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", bindAddr, bindPort))
if err != nil {
return l, err
}
listener, err := net.ListenTCP("tcp", tcpAddr) listener, err := net.ListenTCP("tcp", tcpAddr)
if err != nil { if err != nil {
return l, err return l, err
@ -103,7 +106,7 @@ func NewConn(conn net.Conn) (c *Conn) {
func ConnectServer(host string, port int64) (c *Conn, err error) { func ConnectServer(host string, port int64) (c *Conn, err error) {
c = &Conn{} c = &Conn{}
servertAddr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", host, port)) servertAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil { if err != nil {
return return
} }