Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
33719044
Commit
33719044
authored
Mar 17, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use getty 0.8.2
parent
e7956e69
Hide whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
89 additions
and
82 deletions
+89
-82
change_log.md
echo/tcp-echo/change_log.md
+4
-0
client.go
echo/tcp-echo/client/app/client.go
+1
-1
config.go
echo/tcp-echo/client/app/config.go
+2
-8
main.go
echo/tcp-echo/client/app/main.go
+3
-3
version.go
echo/tcp-echo/client/app/version.go
+1
-1
config.toml
echo/tcp-echo/client/profiles/test/config.toml
+1
-2
config.go
echo/tcp-echo/server/app/config.go
+1
-0
server.go
echo/tcp-echo/server/app/server.go
+7
-4
version.go
echo/tcp-echo/server/app/version.go
+1
-1
config.toml
echo/tcp-echo/server/profiles/test/config.toml
+1
-0
client.go
echo/udp-echo/client/app/client.go
+1
-1
config.go
echo/udp-echo/client/app/config.go
+2
-8
main.go
echo/udp-echo/client/app/main.go
+3
-3
version.go
echo/udp-echo/client/app/version.go
+1
-1
config.toml
echo/udp-echo/client/profiles/test/config.toml
+1
-2
config.go
echo/udp-echo/server/app/config.go
+1
-0
server.go
echo/udp-echo/server/app/server.go
+1
-0
config.toml
echo/udp-echo/server/profiles/test/config.toml
+1
-0
change_log.md
echo/ws-echo/change_log.md
+4
-0
client.go
echo/ws-echo/client/app/client.go
+1
-1
config.go
echo/ws-echo/client/app/config.go
+2
-8
main.go
echo/ws-echo/client/app/main.go
+3
-3
version.go
echo/ws-echo/client/app/version.go
+1
-1
config.toml
echo/ws-echo/client/profiles/test/config.toml
+1
-2
config.go
echo/ws-echo/server/app/config.go
+1
-0
handler.go
echo/ws-echo/server/app/handler.go
+0
-1
server.go
echo/ws-echo/server/app/server.go
+8
-4
version.go
echo/ws-echo/server/app/version.go
+1
-1
config.toml
echo/ws-echo/server/profiles/test/config.toml
+1
-0
change_log.md
echo/wss-echo/change_log.md
+4
-0
client.go
echo/wss-echo/client/app/client.go
+1
-1
config.go
echo/wss-echo/client/app/config.go
+2
-8
main.go
echo/wss-echo/client/app/main.go
+6
-7
version.go
echo/wss-echo/client/app/version.go
+1
-1
config.toml
echo/wss-echo/client/profiles/test/config.toml
+1
-2
config.go
echo/wss-echo/server/app/config.go
+1
-0
handler.go
echo/wss-echo/server/app/handler.go
+0
-1
server.go
echo/wss-echo/server/app/server.go
+15
-5
version.go
echo/wss-echo/server/app/version.go
+1
-1
config.toml
echo/wss-echo/server/profiles/test/config.toml
+1
-0
No files found.
echo/tcp-echo/change_log.md
View file @
33719044
...
...
@@ -10,6 +10,10 @@
## develop history ##
---
-
2018/03/17
> improvement
*
use getty 0.8.2
-
2018/03/14
> improvement
*
add keep alive period
...
...
echo/tcp-echo/client/app/client.go
View file @
33719044
...
...
@@ -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
{
...
...
echo/tcp-echo/client/app/config.go
View file @
33719044
...
...
@@ -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
))
...
...
echo/tcp-echo/client/app/main.go
View file @
33719044
...
...
@@ -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
)
}
...
...
echo/tcp-echo/client/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/tcp-echo/client/profiles/test/config.toml
View file @
33719044
...
...
@@ -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"
echo/tcp-echo/server/app/config.go
View file @
33719044
...
...
@@ -47,6 +47,7 @@ type (
tcpWriteTimeout
time
.
Duration
WaitTimeout
string
`default:"7s"`
waitTimeout
time
.
Duration
MaxMsgLen
int
`default:"1024"`
SessionName
string
`default:"echo-client"`
}
...
...
echo/tcp-echo/server/app/server.go
View file @
33719044
...
...
@@ -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
.
RunEvent
l
oop
(
newSession
)
server
.
RunEvent
L
oop
(
newSession
)
log
.
Debug
(
"server bind addr{%s} ok!"
,
addr
)
serverList
=
append
(
serverList
,
server
)
}
...
...
echo/tcp-echo/server/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/tcp-echo/server/profiles/test/config.toml
View file @
33719044
...
...
@@ -30,4 +30,5 @@ FailFastTimeout = "3s"
TcpReadTimeout
=
"1s"
TcpWriteTimeout
=
"5s"
WaitTimeout
=
"1s"
MaxMsgLen
=
128
SessionName
=
"echo-server"
echo/udp-echo/client/app/client.go
View file @
33719044
...
...
@@ -38,7 +38,7 @@ func init() {
type
EchoClient
struct
{
lock
sync
.
RWMutex
sessions
[]
*
clientEchoSession
gettyClient
*
getty
.
Client
gettyClient
getty
.
Client
serverAddr
net
.
UDPAddr
}
...
...
echo/udp-echo/client/app/config.go
View file @
33719044
...
...
@@ -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
))
...
...
echo/udp-echo/client/app/main.go
View file @
33719044
...
...
@@ -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
}
...
...
echo/udp-echo/client/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/udp-echo/client/profiles/test/config.toml
View file @
33719044
...
...
@@ -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"
echo/udp-echo/server/app/config.go
View file @
33719044
...
...
@@ -43,6 +43,7 @@ type (
udpWriteTimeout
time
.
Duration
WaitTimeout
string
`default:"7s"`
waitTimeout
time
.
Duration
MaxMsgLen
int
`default:"1024"`
SessionName
string
`default:"echo-client"`
}
...
...
echo/udp-echo/server/app/server.go
View file @
33719044
...
...
@@ -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
())
...
...
echo/udp-echo/server/profiles/test/config.toml
View file @
33719044
...
...
@@ -28,4 +28,5 @@ FailFastTimeout = "3s"
UdpReadTimeout
=
"1s"
UdpWriteTimeout
=
"5s"
WaitTimeout
=
"1s"
MaxMsgLen
=
128
SessionName
=
"echo-server"
echo/ws-echo/change_log.md
View file @
33719044
...
...
@@ -10,6 +10,10 @@
## develop history ##
---
-
2018/03/17
> improvement
*
use getty 0.8.2
-
2018/03/09
> improvement
*
use getty 0.8.1
...
...
echo/ws-echo/client/app/client.go
View file @
33719044
...
...
@@ -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
{
...
...
echo/ws-echo/client/app/config.go
View file @
33719044
...
...
@@ -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
))
...
...
echo/ws-echo/client/app/main.go
View file @
33719044
...
...
@@ -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
)
...
...
echo/ws-echo/client/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/ws-echo/client/profiles/test/config.toml
View file @
33719044
...
...
@@ -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"
echo/ws-echo/server/app/config.go
View file @
33719044
...
...
@@ -46,6 +46,7 @@ type (
tcpWriteTimeout
time
.
Duration
WaitTimeout
string
`default:"7s"`
waitTimeout
time
.
Duration
MaxMsgLen
int
`default:"1024"`
SessionName
string
`default:"echo-client"`
}
...
...
echo/ws-echo/server/app/handler.go
View file @
33719044
...
...
@@ -16,7 +16,6 @@ import (
)
import
(
"fmt"
"github.com/AlexStocks/getty"
log
"github.com/AlexStocks/log4go"
)
...
...
echo/ws-echo/server/app/server.go
View file @
33719044
...
...
@@ -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
)
}
...
...
echo/ws-echo/server/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/ws-echo/server/profiles/test/config.toml
View file @
33719044
...
...
@@ -34,4 +34,5 @@ FailFastTimeout = "3s"
TcpReadTimeout
=
"1s"
TcpWriteTimeout
=
"5s"
WaitTimeout
=
"1s"
MaxMsgLen
=
128
SessionName
=
"echo-server"
echo/wss-echo/change_log.md
View file @
33719044
...
...
@@ -10,6 +10,10 @@
## develop history ##
---
-
2018/03/17
> improvement
*
use getty 0.8.2
-
2018/03/10
> improvement
*
using getty 0.8.1
...
...
echo/wss-echo/client/app/client.go
View file @
33719044
...
...
@@ -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
{
...
...
echo/wss-echo/client/app/config.go
View file @
33719044
...
...
@@ -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
))
...
...
echo/wss-echo/client/app/main.go
View file @
33719044
...
...
@@ -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
)),
)
}
...
...
echo/wss-echo/client/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/wss-echo/client/profiles/test/config.toml
View file @
33719044
...
...
@@ -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"
echo/wss-echo/server/app/config.go
View file @
33719044
...
...
@@ -46,6 +46,7 @@ type (
tcpWriteTimeout
time
.
Duration
WaitTimeout
string
`default:"7s"`
waitTimeout
time
.
Duration
MaxMsgLen
int
`default:"1024"`
SessionName
string
`default:"echo-client"`
}
...
...
echo/wss-echo/server/app/handler.go
View file @
33719044
...
...
@@ -16,7 +16,6 @@ import (
)
import
(
"fmt"
"github.com/AlexStocks/getty"
log
"github.com/AlexStocks/log4go"
)
...
...
echo/wss-echo/server/app/server.go
View file @
33719044
...
...
@@ -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
.
RunEvent
l
oop
(
newSession
)
server
.
RunEvent
L
oop
(
newSession
)
// run server
serverList
=
append
(
serverList
,
server
)
}
...
...
echo/wss-echo/server/app/version.go
View file @
33719044
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
echo/wss-echo/server/profiles/test/config.toml
View file @
33719044
...
...
@@ -39,4 +39,5 @@ KeyFile = "./conf/cert/server.key"
TcpReadTimeout
=
"1s"
TcpWriteTimeout
=
"5s"
WaitTimeout
=
"1s"
MaxMsgLen
=
128
SessionName
=
"echo-server"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment