Commit 2403c0eb authored by wei.xuan's avatar wei.xuan

feat:local addr

parent ab3fd8ec
...@@ -24,7 +24,6 @@ import ( ...@@ -24,7 +24,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net" "net"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
...@@ -111,31 +110,6 @@ func NewUDPClient(opts ...ClientOption) Client { ...@@ -111,31 +110,6 @@ func NewUDPClient(opts ...ClientOption) Client {
return newClient(UDP_CLIENT, opts...) return newClient(UDP_CLIENT, opts...)
} }
// NewWSClient builds a ws client.
func NewWSClient(opts ...ClientOption) Client {
c := newClient(WS_CLIENT, opts...)
if !strings.HasPrefix(c.addr, "ws://") {
panic(fmt.Sprintf("the prefix @serverAddr:%s is not ws://", c.addr))
}
return c
}
// NewWSSClient function builds a wss client.
func NewWSSClient(opts ...ClientOption) Client {
c := newClient(WSS_CLIENT, opts...)
if c.cert == "" {
panic(fmt.Sprintf("@cert:%s", c.cert))
}
if !strings.HasPrefix(c.addr, "wss://") {
panic(fmt.Sprintf("the prefix @serverAddr:%s is not wss://", c.addr))
}
return c
}
func (c *client) ID() EndPointID { func (c *client) ID() EndPointID {
return c.endPointID return c.endPointID
} }
......
...@@ -101,6 +101,7 @@ type ClientOption func(*ClientOptions) ...@@ -101,6 +101,7 @@ type ClientOption func(*ClientOptions)
type ClientOptions struct { type ClientOptions struct {
addr string addr string
laddr string // local addr
number int number int
reconnectInterval int // reConnect Interval reconnectInterval int // reConnect Interval
...@@ -123,6 +124,13 @@ func WithServerAddress(addr string) ClientOption { ...@@ -123,6 +124,13 @@ func WithServerAddress(addr string) ClientOption {
} }
} }
// WithLocalAddressClient @addr is server address.
func WithLocalAddressClient(addr string) ClientOption {
return func(o *ClientOptions) {
o.laddr = addr
}
}
// WithReconnectInterval @reconnectInterval is server address. // WithReconnectInterval @reconnectInterval is server address.
func WithReconnectInterval(reconnectInterval int) ClientOption { func WithReconnectInterval(reconnectInterval int) ClientOption {
return func(o *ClientOptions) { return func(o *ClientOptions) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment