Commit 33719044 authored by AlexStocks's avatar AlexStocks

use getty 0.8.2

parent e7956e69
......@@ -10,6 +10,10 @@
## develop history ##
---
- 2018/03/17
> improvement
* use getty 0.8.2
- 2018/03/14
> improvement
* add keep alive period
......
......@@ -37,7 +37,7 @@ func init() {
type EchoClient struct {
lock sync.RWMutex
sessions []*clientEchoSession
gettyClient *getty.Client
gettyClient getty.Client
}
func (this *EchoClient) isAvailable() bool {
......
......@@ -47,6 +47,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......@@ -62,9 +63,7 @@ type (
ProfilePort int `default:"10086"`
// session pool
ConnectionNum int `default:"16"`
ConnectInterval string `default:"5s"`
connectInterval time.Duration
ConnectionNum int `default:"16"`
// heartbeat
HeartbeatPeriod string `default:"15s"`
......@@ -105,11 +104,6 @@ func initConf() {
}
conf = new(Config)
config.MustLoadWithPath(confFile, conf)
conf.connectInterval, err = time.ParseDuration(conf.ConnectInterval)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(ConnectionInterval{%#v}) = error{%v}", conf.ConnectInterval, err))
return
}
conf.heartbeatPeriod, err = time.ParseDuration(conf.HeartbeatPeriod)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(HeartbeatPeroid{%#v}) = error{%v}", conf.HeartbeatPeriod, err))
......
......@@ -95,6 +95,7 @@ func newSession(session getty.Session) error {
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -111,9 +112,8 @@ func newSession(session getty.Session) error {
func initClient() {
client.gettyClient = getty.NewTCPClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.HostAddress(conf.ServerHost, conf.ServerPort),
getty.WithServerAddress(gxnet.HostAddress(conf.ServerHost, conf.ServerPort)),
getty.WithConnectionNumber((int)(conf.ConnectionNum)),
)
client.gettyClient.RunEventLoop(newSession)
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -15,8 +15,6 @@ ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
......@@ -46,4 +44,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-client"
......@@ -47,6 +47,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......
......@@ -39,7 +39,7 @@ var (
)
var (
serverList []*getty.Server
serverList []getty.Server
)
func main() {
......@@ -96,6 +96,7 @@ func newSession(session getty.Session) error {
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -114,7 +115,7 @@ func initServer() {
var (
addr string
portList []string
server *getty.Server
server getty.Server
)
// if *host == "" {
......@@ -132,9 +133,11 @@ func initServer() {
}
for _, port := range portList {
addr = gxnet.HostAddress2(conf.Host, port)
server = getty.NewTCPServer(addr)
server = getty.NewTCPServer(
getty.WithLocalAddress(addr),
)
// run server
server.RunEventloop(newSession)
server.RunEventLoop(newSession)
log.Debug("server bind addr{%s} ok!", addr)
serverList = append(serverList, server)
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -30,4 +30,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-server"
......@@ -38,7 +38,7 @@ func init() {
type EchoClient struct {
lock sync.RWMutex
sessions []*clientEchoSession
gettyClient *getty.Client
gettyClient getty.Client
serverAddr net.UDPAddr
}
......
......@@ -43,6 +43,7 @@ type (
udpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......@@ -58,9 +59,7 @@ type (
ProfilePort int `default:"10086"`
// session pool
ConnectionNum int `default:"16"`
ConnectInterval string `default:"5s"`
connectInterval time.Duration
ConnectionNum int `default:"16"`
// heartbeat
HeartbeatPeriod string `default:"15s"`
......@@ -102,11 +101,6 @@ func initConf() {
conf = new(Config)
config.MustLoadWithPath(confFile, conf)
conf.connectInterval, err = time.ParseDuration(conf.ConnectInterval)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(ConnectionInterval{%#v}) = error{%v}", conf.ConnectInterval, err))
return
}
conf.heartbeatPeriod, err = time.ParseDuration(conf.HeartbeatPeriod)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(HeartbeatPeroid{%#v}) = error{%v}", conf.HeartbeatPeriod, err))
......
......@@ -90,6 +90,7 @@ func newSession(session getty.Session) error {
udpConn.SetReadBuffer(conf.GettySessionParam.UdpRBufSize)
udpConn.SetWriteBuffer(conf.GettySessionParam.UdpWBufSize)
session.SetMaxMsgLen(conf.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -106,9 +107,8 @@ func newSession(session getty.Session) error {
func initClient() {
client.gettyClient = getty.NewUDPClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.HostAddress(conf.ServerHost, conf.ServerPort),
getty.WithServerAddress(gxnet.HostAddress(conf.ServerHost, conf.ServerPort)),
getty.WithConnectionNumber((int)(conf.ConnectionNum)),
)
client.gettyClient.RunEventLoop(newSession)
client.serverAddr = net.UDPAddr{IP: net.ParseIP(conf.ServerHost), Port: conf.ServerPort}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -15,8 +15,6 @@ ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
......@@ -43,4 +41,5 @@ FailFastTimeout = "3s"
UdpReadTimeout = "1s"
UdpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-client"
......@@ -43,6 +43,7 @@ type (
udpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......
......@@ -92,6 +92,7 @@ func newSession(session getty.Session) error {
udpConn.SetReadBuffer(conf.GettySessionParam.UdpRBufSize)
udpConn.SetWriteBuffer(conf.GettySessionParam.UdpWBufSize)
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......
......@@ -28,4 +28,5 @@ FailFastTimeout = "3s"
UdpReadTimeout = "1s"
UdpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-server"
......@@ -10,6 +10,10 @@
## develop history ##
---
- 2018/03/17
> improvement
* use getty 0.8.2
- 2018/03/09
> improvement
* use getty 0.8.1
......
......@@ -36,7 +36,7 @@ func init() {
type EchoClient struct {
lock sync.RWMutex
sessions []*clientEchoSession
gettyClient *getty.Client
gettyClient getty.Client
}
func (this *EchoClient) isAvailable() bool {
......
......@@ -46,6 +46,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......@@ -62,9 +63,7 @@ type (
ProfilePort int `default:"10086"`
// session pool
ConnectionNum int `default:"16"`
ConnectInterval string `default:"5s"`
connectInterval time.Duration
ConnectionNum int `default:"16"`
// heartbeat
HeartbeatPeriod string `default:"15s"`
......@@ -105,11 +104,6 @@ func initConf() {
}
conf = new(Config)
config.MustLoadWithPath(confFile, conf)
conf.connectInterval, err = time.ParseDuration(conf.ConnectInterval)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(ConnectionInterval{%#v}) = error{%v}", conf.ConnectInterval, err))
return
}
conf.heartbeatPeriod, err = time.ParseDuration(conf.HeartbeatPeriod)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(HeartbeatPeroid{%#v}) = error{%v}", conf.HeartbeatPeriod, err))
......
......@@ -96,6 +96,7 @@ func newSession(session getty.Session) error {
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
}
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -112,9 +113,8 @@ func newSession(session getty.Session) error {
func initClient() {
client.gettyClient = getty.NewWSClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.WSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath),
getty.WithServerAddress(gxnet.WSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath)),
getty.WithConnectionNumber((int)(conf.ConnectionNum)),
)
client.gettyClient.RunEventLoop(newSession)
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -17,8 +17,6 @@ ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
......@@ -49,4 +47,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-client"
......@@ -46,6 +46,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......
......@@ -16,7 +16,6 @@ import (
)
import (
"fmt"
"github.com/AlexStocks/getty"
log "github.com/AlexStocks/log4go"
)
......
......@@ -40,7 +40,7 @@ var (
)
var (
serverList []*getty.Server
serverList []getty.Server
)
func main() {
......@@ -101,6 +101,7 @@ func newSession(session getty.Session) error {
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
}
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -120,7 +121,7 @@ func initServer() {
addr string
portList []string
pathList []string
server *getty.Server
server getty.Server
)
// if *host == "" {
......@@ -147,8 +148,11 @@ func initServer() {
// addr = *host + ":" + port
// addr = conf.Host + ":" + port
addr = gxnet.HostAddress2(conf.Host, port)
server = getty.NewWSServer(addr, pathList[idx])
server.RunEventloop(newSession)
server = getty.NewWSServer(
getty.WithLocalAddress(addr),
getty.WithWebsocketServerPath(pathList[idx]),
)
server.RunEventLoop(newSession)
log.Debug("server bind addr{ws://%s/%s} ok!", addr, pathList[idx])
serverList = append(serverList, server)
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -34,4 +34,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-server"
......@@ -10,6 +10,10 @@
## develop history ##
---
- 2018/03/17
> improvement
* use getty 0.8.2
- 2018/03/10
> improvement
* using getty 0.8.1
......
......@@ -36,7 +36,7 @@ func init() {
type EchoClient struct {
lock sync.RWMutex
sessions []*clientEchoSession
gettyClient *getty.Client
gettyClient getty.Client
}
func (this *EchoClient) isAvailable() bool {
......
......@@ -46,6 +46,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......@@ -66,9 +67,7 @@ type (
CertFile string
// session pool
ConnectionNum int `default:"16"`
ConnectInterval string `default:"5s"`
connectInterval time.Duration
ConnectionNum int `default:"16"`
// heartbeat
HeartbeatPeriod string `default:"15s"`
......@@ -109,11 +108,6 @@ func initConf() {
}
conf = new(Config)
config.MustLoadWithPath(confFile, conf)
conf.connectInterval, err = time.ParseDuration(conf.ConnectInterval)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(ConnectionInterval{%#v}) = error{%v}", conf.ConnectInterval, err))
return
}
conf.heartbeatPeriod, err = time.ParseDuration(conf.HeartbeatPeriod)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(HeartbeatPeroid{%#v}) = error{%v}", conf.HeartbeatPeriod, err))
......
......@@ -96,6 +96,7 @@ func newSession(session getty.Session) error {
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
}
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -113,16 +114,14 @@ func newSession(session getty.Session) error {
func initClient() {
if conf.WSSEnable {
client.gettyClient = getty.NewWSSClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.WSSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath),
conf.CertFile,
getty.WithServerAddress(gxnet.WSSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath)),
getty.WithConnectionNumber((int)(conf.ConnectionNum)),
getty.WithRootCertificateFile(conf.CertFile),
)
} else {
client.gettyClient = getty.NewWSClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.WSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath),
getty.WithServerAddress(gxnet.WSSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath)),
getty.WithConnectionNumber((int)(conf.ConnectionNum)),
)
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -21,8 +21,6 @@ CertFile = "./conf/cert/client.crt"
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
......@@ -53,4 +51,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-client"
......@@ -46,6 +46,7 @@ type (
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
MaxMsgLen int `default:"1024"`
SessionName string `default:"echo-client"`
}
......
......@@ -16,7 +16,6 @@ import (
)
import (
"fmt"
"github.com/AlexStocks/getty"
log "github.com/AlexStocks/log4go"
)
......
......@@ -40,7 +40,7 @@ var (
)
var (
serverList []*getty.Server
serverList []getty.Server
)
func main() {
......@@ -101,6 +101,7 @@ func newSession(session getty.Session) error {
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
}
session.SetMaxMsgLen(conf.GettySessionParam.MaxMsgLen)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
......@@ -120,7 +121,7 @@ func initServer() {
addr string
portList []string
pathList []string
server *getty.Server
server getty.Server
)
// if *host == "" {
......@@ -147,13 +148,22 @@ func initServer() {
addr = gxnet.HostAddress2(conf.Host, port)
if conf.CertFile != "" && conf.KeyFile != "" {
server = getty.NewWSSServer(addr, pathList[idx], conf.CertFile, conf.KeyFile, conf.CACert)
server = getty.NewWSSServer(
getty.WithLocalAddress(addr),
getty.WithWebsocketServerPath(pathList[idx]),
getty.WithWebsocketServerCert(conf.CertFile),
getty.WithWebsocketServerPrivateKey(conf.KeyFile),
getty.WithWebsocketServerRootCert(conf.CACert),
)
log.Debug("server bind addr{wss://%s/%s} ok!", addr, pathList[idx])
} else {
server = getty.NewWSServer(addr, pathList[idx])
server = getty.NewWSServer(
getty.WithLocalAddress(addr),
getty.WithWebsocketServerPath(pathList[idx]),
)
log.Debug("server bind addr{ws://%s/%s} ok!", addr, pathList[idx])
}
server.RunEventloop(newSession)
server.RunEventLoop(newSession)
// run server
serverList = append(serverList, server)
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.1"
Version = "0.8.2"
)
......@@ -39,4 +39,5 @@ KeyFile = "./conf/cert/server.key"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
SessionName = "echo-server"
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