整理日志与ping自定义

This commit is contained in:
boyce
2019-03-22 18:23:29 +08:00
parent 9e75434152
commit 7f5fdca0cf
2 changed files with 11 additions and 8 deletions

View File

@@ -16,7 +16,7 @@ import (
//IWebsocketClient ...
type IWebsocketClient interface {
Init(slf IWebsocketClient, strurl, strPath string, bproxy bool, timeoutsec time.Duration) error
Init(slf IWebsocketClient, strurl, strProxyPath string, timeoutsec time.Duration) error
Start() error
WriteMessage(msg []byte) error
OnDisconnect() error
@@ -36,16 +36,17 @@ type WebsocketClient struct {
timeoutsec time.Duration
bRun bool
ping string
}
//Init ...
func (ws *WebsocketClient) Init(slf IWebsocketClient, strurl, strPath string, bproxy bool, timeoutsec time.Duration) error {
func (ws *WebsocketClient) Init(slf IWebsocketClient, strurl, strProxyPath string, timeoutsec time.Duration) error {
ws.timeoutsec = timeoutsec
ws.slf = slf
if bproxy == true {
if strProxyPath != "" {
proxy := func(_ *http.Request) (*url.URL, error) {
return url.Parse(strPath)
return url.Parse(strProxyPath)
}
if timeoutsec > 0 {
@@ -65,10 +66,14 @@ func (ws *WebsocketClient) Init(slf IWebsocketClient, strurl, strPath string, bp
ws.url = strurl
ws.bwritemsg = make(chan []byte, 1000)
ws.ping = `ping`
return nil
}
func (ws *WebsocketClient) SetPing(ping string) {
ws.ping = ping
}
//OnRun ...
func (ws *WebsocketClient) OnRun() error {
for {
@@ -145,7 +150,7 @@ func (ws *WebsocketClient) writeMsg() error {
select {
case <-timerC:
if ws.state == 2 {
ws.WriteMessage([]byte(`ping`))
ws.WriteMessage([]byte(ws.ping))
}
case msg := <-ws.bwritemsg:
if ws.state == 2 {

View File

@@ -121,7 +121,6 @@ func (slf *WebsocketServer) startListen() {
if err != nil {
service.GetLogger().Printf(sysmodule.LEVER_FATAL, "http.ListenAndServe(%d, nil) error:%v\n", slf.port, err)
fmt.Printf("http.ListenAndServe(%d, nil) error\n", slf.port)
os.Exit(1)
}
}
@@ -159,7 +158,6 @@ func (slf *WebsocketServer) Disconnect(clientid uint64) {
}
value.conn.Close()
//slf.ReleaseClient(value)
}
func (slf *WebsocketServer) Stop() {