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
e7956e69
Commit
e7956e69
authored
Mar 17, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update udp echo server by getty v0.8.2
parent
9a265ed1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
30 additions
and
22 deletions
+30
-22
change_log.md
echo/udp-echo/change_log.md
+4
-0
client.go
echo/udp-echo/client/app/client.go
+3
-1
config.go
echo/udp-echo/client/app/config.go
+0
-4
handler.go
echo/udp-echo/client/app/handler.go
+2
-2
main.go
echo/udp-echo/client/app/main.go
+12
-7
readwriter.go
echo/udp-echo/client/app/readwriter.go
+1
-2
log.xml
echo/udp-echo/client/profiles/test/log.xml
+1
-1
server.go
echo/udp-echo/server/app/server.go
+6
-4
version.go
echo/udp-echo/server/app/version.go
+1
-1
No files found.
echo/udp-echo/change_log.md
View file @
e7956e69
...
...
@@ -10,6 +10,10 @@
## develop history ##
---
-
2018/03/17
> improvement
*
use getty v0.8.2
-
2018/03/16
> bug fix
*
forbid close udp session in OnCron
...
...
echo/udp-echo/client/app/client.go
View file @
e7956e69
...
...
@@ -19,6 +19,7 @@ import (
import
(
"github.com/AlexStocks/getty"
log
"github.com/AlexStocks/log4go"
"net"
)
var
(
...
...
@@ -38,6 +39,7 @@ type EchoClient struct {
lock
sync
.
RWMutex
sessions
[]
*
clientEchoSession
gettyClient
*
getty
.
Client
serverAddr
net
.
UDPAddr
}
func
(
this
*
EchoClient
)
isAvailable
()
bool
{
...
...
@@ -160,7 +162,7 @@ func (this *EchoClient) heartbeat(session getty.Session) {
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
)
+
1
)
ctx
.
Pkg
=
&
pkg
ctx
.
PeerAddr
=
&
(
conf
.
serverAddr
)
ctx
.
PeerAddr
=
&
(
this
.
serverAddr
)
if
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
);
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, context{%#v}) = error{%v}"
,
session
.
Stat
(),
ctx
,
err
)
...
...
echo/udp-echo/client/app/config.go
View file @
e7956e69
...
...
@@ -19,7 +19,6 @@ import (
import
(
log
"github.com/AlexStocks/log4go"
config
"github.com/koding/multiconfig"
"net"
)
const
(
...
...
@@ -57,7 +56,6 @@ type (
ServerHost
string
`default:"127.0.0.1"`
ServerPort
int
`default:"10000"`
ProfilePort
int
`default:"10086"`
serverAddr
net
.
UDPAddr
// session pool
ConnectionNum
int
`default:"16"`
...
...
@@ -104,8 +102,6 @@ func initConf() {
conf
=
new
(
Config
)
config
.
MustLoadWithPath
(
confFile
,
conf
)
conf
.
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
conf
.
connectInterval
,
err
=
time
.
ParseDuration
(
conf
.
ConnectInterval
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"time.ParseDuration(ConnectionInterval{%#v}) = error{%v}"
,
conf
.
ConnectInterval
,
err
))
...
...
echo/udp-echo/client/app/handler.go
View file @
e7956e69
...
...
@@ -80,8 +80,8 @@ func (this *EchoMessageHandler) OnCron(session getty.Session) {
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
session
.
GetActive
())
.
Nanoseconds
()
{
log
.
Warn
(
"session{%s} timeout{%s}, reqNum{%d}"
,
session
.
Stat
(),
time
.
Since
(
session
.
GetActive
())
.
String
(),
clientEchoSession
.
reqNum
)
client
.
removeSession
(
session
)
return
//
client.removeSession(session)
//
return
}
client
.
heartbeat
(
session
)
...
...
echo/udp-echo/client/app/main.go
View file @
e7956e69
...
...
@@ -111,6 +111,7 @@ func initClient() {
gxnet
.
HostAddress
(
conf
.
ServerHost
,
conf
.
ServerPort
),
)
client
.
gettyClient
.
RunEventLoop
(
newSession
)
client
.
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
}
func
uninitClient
()
{
...
...
@@ -146,7 +147,7 @@ func initSignal() {
}
}
func
echo
()
{
func
echo
(
serverAddr
*
net
.
UDPAddr
)
{
var
(
pkg
EchoPackage
ctx
getty
.
UDPContext
...
...
@@ -161,7 +162,7 @@ func echo() {
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
+
1
ctx
.
Pkg
=
&
pkg
ctx
.
PeerAddr
=
&
(
conf
.
serverAddr
)
ctx
.
PeerAddr
=
serverAddr
if
session
:=
client
.
selectSession
();
session
!=
nil
{
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
)
...
...
@@ -174,6 +175,12 @@ func echo() {
}
func
test
()
{
var
(
cost
int64
serverAddr
net
.
UDPAddr
counter
gxtime
.
CountWatch
)
for
{
if
client
.
isAvailable
()
{
break
...
...
@@ -181,13 +188,11 @@ func test() {
time
.
Sleep
(
1e6
)
}
var
(
cost
int64
counter
gxtime
.
CountWatch
)
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
counter
.
Start
()
for
i
:=
0
;
i
<
conf
.
EchoTimes
;
i
++
{
echo
()
echo
(
&
serverAddr
)
}
cost
=
counter
.
Count
()
log
.
Info
(
"after loop %d times, echo cost %d ms"
,
conf
.
EchoTimes
,
cost
/
1e6
)
...
...
echo/udp-echo/client/app/readwriter.go
View file @
e7956e69
...
...
@@ -21,8 +21,7 @@ import (
log
"github.com/AlexStocks/log4go"
)
type
EchoPackageHandler
struct
{
}
type
EchoPackageHandler
struct
{}
func
NewEchoPackageHandler
()
*
EchoPackageHandler
{
return
&
EchoPackageHandler
{}
...
...
echo/udp-echo/client/profiles/test/log.xml
View file @
e7956e69
...
...
@@ -5,7 +5,7 @@
<!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
<level>
DEBUG
</level>
</filter>
<filter
enabled=
"
fals
e"
>
<filter
enabled=
"
tru
e"
>
<tag>
debug_file
</tag>
<type>
file
</type>
<level>
DEBUG
</level>
...
...
echo/udp-echo/server/app/server.go
View file @
e7956e69
...
...
@@ -39,7 +39,7 @@ var (
)
var
(
serverList
[]
*
getty
.
Server
serverList
[]
getty
.
Server
)
func
main
()
{
...
...
@@ -110,7 +110,7 @@ func initServer() {
var
(
addr
string
portList
[]
string
server
*
getty
.
Server
server
getty
.
Server
)
// if *host == "" {
...
...
@@ -128,9 +128,11 @@ func initServer() {
}
for
_
,
port
:=
range
portList
{
addr
=
gxnet
.
HostAddress2
(
conf
.
Host
,
port
)
server
=
getty
.
NewUDPPServer
(
addr
)
server
=
getty
.
NewUDPPServer
(
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/udp-echo/server/app/version.go
View file @
e7956e69
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
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