1 Star 0 Fork 0

simple/simple.io

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
example.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
simple 提交于 2024-11-17 20:24 . perf(example): 完善示例
package main
import (
"gitee.com/simple-set/simple.io/src/event"
"gitee.com/simple-set/simple.io/src/process/http"
"gitee.com/simple-set/simple.io/src/process/socks"
"log"
)
type Example struct {
bootServer *event.BootServer
bootClient *event.BootClient
}
func NewServer() *Example {
return &Example{bootServer: event.NewBootServer(), bootClient: event.NewBootClient()}
}
func (s *Example) register(process event.Process) {
s.bootServer.Register(process)
s.bootClient.Register(process)
}
func (s *Example) httpServer() error {
s.register(http.NewRequestProcess())
s.register(NewHttpServer())
s.register(http.NewResponseProcess())
return s.bootServer.ListenTcp(":8080")
}
func (s *Example) httpProxy() error {
s.register(http.NewRequestProcess())
s.register(NewHttpProxy())
return s.bootServer.ListenTcp(":8080")
}
func (s *Example) socksServer() error {
process := socks.NewProcess()
process.SetConnect(NewConnectHandler())
process.AddAuthenticator(NewAuthUserPass())
process.SetNoAuth(true)
s.register(process)
return s.bootServer.ListenTcp(":8080")
}
func (s *Example) echoServerUDP() error {
s.register(NewEchoServer())
return s.bootServer.ListenUdp(":8080")
}
func (s *Example) echoClientUDP() error {
s.register(NewEchoClient())
if starterClient, err := s.bootClient.DialUdp("127.0.0.1:8080"); err == nil {
_, err = starterClient.Request(nil)
return err
} else {
return err
}
}
func main() {
server := NewServer()
if err := server.echoClientUDP(); err != nil {
log.Fatalln(err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/simple-set/simple.io.git
git@gitee.com:simple-set/simple.io.git
simple-set
simple.io
simple.io
v1.5.3

搜索帮助