Skip to content

Commit

Permalink
Merge pull request #13 from piaodazhu/dev
Browse files Browse the repository at this point in the history
fix tunnel close bug & add a cli example
  • Loading branch information
piaodazhu authored Oct 8, 2023
2 parents 1e575d6 + ca3ebfa commit 3adc994
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions example/cli/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module cli

go 1.12

// require github.com/piaodazhu/proxylite v0.0.0-20230813091435-b2c8f474a9fc
replace github.com/piaodazhu/proxylite => ../../

require github.com/piaodazhu/proxylite v0.0.0-00010101000000-000000000000
28 changes: 28 additions & 0 deletions example/cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"flag"

"github.com/piaodazhu/proxylite"
)

func main() {
var name string
flag.StringVar(&name, "n", "abc", "service name")
flag.Parse()
cli := proxylite.NewProxyLiteClient(":9933")
port, ok := cli.AnyPort()
if !ok {
panic("anyport() error")
}
_, done, err := cli.RegisterInnerService(proxylite.RegisterInfo{
OuterPort: port,
InnerAddr: ":123",
Name: name,
Message: "hello world",
}, proxylite.ControlInfo{})
if err != nil {
panic(err)
}
<-done
}
2 changes: 1 addition & 1 deletion example/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import "github.com/piaodazhu/proxylite"

func main() {
server := proxylite.NewProxyLiteServer()
server.AddPort(9930, 9932)
server.AddPort(9940, 9948)
panic(server.Run(":9933"))
}
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (s *ProxyLiteServer) startTunnel(tn *tunnel) {
listener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", tn.service.Port))
if err != nil {
(*tn.innerConn).Close()
tn.empty = true
return
}

Expand Down

0 comments on commit 3adc994

Please sign in to comment.