mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
增加DialWith,可以自定义连接,配置NewHostDial,可以实现断开连接切换服务
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/injoyai/conv"
|
"github.com/injoyai/conv"
|
||||||
"github.com/injoyai/ios"
|
"github.com/injoyai/ios"
|
||||||
"github.com/injoyai/ios/client"
|
"github.com/injoyai/ios/client"
|
||||||
"github.com/injoyai/ios/client/dial"
|
"github.com/injoyai/ios/module/tcp"
|
||||||
"github.com/injoyai/logs"
|
"github.com/injoyai/logs"
|
||||||
"github.com/injoyai/tdx/protocol"
|
"github.com/injoyai/tdx/protocol"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -35,13 +35,18 @@ func Dial(addr string, op ...client.Option) (cli *Client, err error) {
|
|||||||
if !strings.Contains(addr, ":") {
|
if !strings.Contains(addr, ":") {
|
||||||
addr += ":7709"
|
addr += ":7709"
|
||||||
}
|
}
|
||||||
|
return DialWith(tcp.NewDial(addr), op...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialWith 与服务器建立连接
|
||||||
|
func DialWith(dial ios.DialFunc, op ...client.Option) (cli *Client, err error) {
|
||||||
|
|
||||||
cli = &Client{
|
cli = &Client{
|
||||||
Wait: wait.New(time.Second * 2),
|
Wait: wait.New(time.Second * 2),
|
||||||
m: maps.NewSafe(),
|
m: maps.NewSafe(),
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.Client, err = dial.TCP(addr, func(c *client.Client) {
|
cli.Client, err = client.Dial(dial, func(c *client.Client) {
|
||||||
c.Logger.Debug(false) //关闭日志打印
|
c.Logger.Debug(false) //关闭日志打印
|
||||||
c.Logger.WithHEX() //以HEX显示
|
c.Logger.WithHEX() //以HEX显示
|
||||||
c.SetOption(op...) //自定义选项
|
c.SetOption(op...) //自定义选项
|
||||||
|
|||||||
Reference in New Issue
Block a user