-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d73a2c
commit 6a3ca49
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
"waffle/internal/proxy" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
go func() { | ||
if err := tcpDummy(); err != nil { | ||
log.Panicf("dummy: %s", err.Error()) | ||
} | ||
}() | ||
|
||
sender := proxy.NewTCPSender("127.0.0.1:8083", "127.0.0.1:8081") | ||
receiver := proxy.NewTCPReceiver("127.0.0.1:8080", sender) | ||
|
||
if err := sender.Start(ctx); err != nil { | ||
log.Panicf("start sender: %s", err.Error()) | ||
} | ||
|
||
if err := receiver.Run(); err != nil { | ||
log.Panicf("run receiver: %s", err.Error()) | ||
} | ||
} | ||
|
||
func tcpDummy() error { | ||
addr, err := net.ResolveTCPAddr("tcp", ":8081") | ||
if err != nil { | ||
return fmt.Errorf("resolve tcp addr: %w", err) | ||
} | ||
|
||
listener, err := net.ListenTCP("tcp", addr) | ||
if err != nil { | ||
return fmt.Errorf("listen tcp: %w", err) | ||
} | ||
|
||
for { | ||
conn, err := listener.Accept() | ||
if err != nil { | ||
return fmt.Errorf("liistener accept: %w", err) | ||
} | ||
|
||
log.Println(conn) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters