Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tunnel close bug & add a cli example #13

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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