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

feat:local addr

parent ab3fd8ec
......@@ -24,7 +24,6 @@ import (
"fmt"
"io/ioutil"
"net"
"strings"
"sync"
"sync/atomic"
"time"
......@@ -111,31 +110,6 @@ func NewUDPClient(opts ...ClientOption) Client {
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 {
return c.endPointID
}
......
......@@ -101,6 +101,7 @@ type ClientOption func(*ClientOptions)
type ClientOptions struct {
addr string
laddr string // local addr
number int
reconnectInterval int // reConnect Interval
......@@ -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.
func WithReconnectInterval(reconnectInterval int) ClientOption {
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