Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
signal
traffic-signal-platform
Commits
884e7b9d
Commit
884e7b9d
authored
May 17, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 代码优化
parent
2cf9aad7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
4 deletions
+3
-4
NettyClient.java
...ervice/src/main/java/net/wanji/com/netty/NettyClient.java
+2
-2
HeartBeatService.java
...a/net/wanji/com/netty/response/impl/HeartBeatService.java
+1
-2
No files found.
signal-utc-dt-service/src/main/java/net/wanji/com/netty/NettyClient.java
View file @
884e7b9d
...
@@ -49,18 +49,18 @@ public class NettyClient {
...
@@ -49,18 +49,18 @@ public class NettyClient {
@Override
@Override
protected
void
initChannel
(
NioSocketChannel
socketChannel
)
{
protected
void
initChannel
(
NioSocketChannel
socketChannel
)
{
log
.
info
(
"新增客户端连接ip:{},port:{}"
,
socketChannel
.
remoteAddress
().
getHostString
(),
socketChannel
.
remoteAddress
().
getPort
());
log
.
info
(
"新增客户端连接ip:{},port:{}"
,
socketChannel
.
remoteAddress
().
getHostString
(),
socketChannel
.
remoteAddress
().
getPort
());
socketChannel
.
writeAndFlush
(
"2a320d0a24340d0a415554480d0a2431360d0a536d2a674234504742333939514241390d0a"
);
log
.
info
(
"发送密码。。。"
);
log
.
info
(
"发送密码。。。"
);
socketChannel
.
pipeline
()
socketChannel
.
pipeline
()
.
addLast
(
new
LengthFieldBasedFrameDecoder
(
ByteOrder
.
LITTLE_ENDIAN
,
Integer
.
MAX_VALUE
,
4
,
2
,
0
,
0
,
true
))
.
addLast
(
new
LengthFieldBasedFrameDecoder
(
ByteOrder
.
LITTLE_ENDIAN
,
Integer
.
MAX_VALUE
,
4
,
2
,
0
,
0
,
true
))
.
addLast
(
new
NettyServerHandler
(
threadPoolExecutor
));
.
addLast
(
new
NettyServerHandler
(
threadPoolExecutor
));
channelGroup
.
add
(
socketChannel
);
channelGroup
.
add
(
socketChannel
);
socketChannel
.
writeAndFlush
(
"2a320d0a24340d0a415554480d0a2431360d0a536d2a674234504742333939514241390d0a"
);
String
key
=
StringUtils
.
join
(
socketChannel
.
remoteAddress
().
getHostString
(),
":"
.
intern
(),
socketChannel
.
remoteAddress
().
getPort
());
String
key
=
StringUtils
.
join
(
socketChannel
.
remoteAddress
().
getHostString
(),
":"
.
intern
(),
socketChannel
.
remoteAddress
().
getPort
());
IP_PORT_CHANNEL_ID_MAP
.
put
(
key
,
socketChannel
.
id
());
IP_PORT_CHANNEL_ID_MAP
.
put
(
key
,
socketChannel
.
id
());
log
.
info
(
"{}:客户端连接成功"
,
key
);
log
.
info
(
"{}:客户端连接成功"
,
key
);
}
}
});
});
ChannelFuture
channelFuture
=
bootstrap
.
bind
(
local
Port
).
sync
();
ChannelFuture
channelFuture
=
bootstrap
.
bind
(
remote
Port
).
sync
();
log
.
info
(
"server is started in {}"
,
channelFuture
.
channel
().
localAddress
());
log
.
info
(
"server is started in {}"
,
channelFuture
.
channel
().
localAddress
());
//收到停止信号
//收到停止信号
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(()
->
{
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(()
->
{
...
...
signal-utc-dt-service/src/main/java/net/wanji/com/netty/response/impl/HeartBeatService.java
View file @
884e7b9d
...
@@ -9,7 +9,6 @@ import net.wanji.com.netty.pojo.CommandPojo;
...
@@ -9,7 +9,6 @@ import net.wanji.com.netty.pojo.CommandPojo;
import
net.wanji.com.netty.response.CommandResponseService
;
import
net.wanji.com.netty.response.CommandResponseService
;
import
net.wanji.com.pojo.netty.MessageResultPojo
;
import
net.wanji.com.pojo.netty.MessageResultPojo
;
import
net.wanji.com.util.CRC16Utils
;
import
net.wanji.com.util.CRC16Utils
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
/**
/**
...
@@ -28,7 +27,7 @@ public class HeartBeatService implements CommandResponseService {
...
@@ -28,7 +27,7 @@ public class HeartBeatService implements CommandResponseService {
return
heartBeatRequest
;
return
heartBeatRequest
;
}
}
@Scheduled
(
fixedRate
=
1000
)
//
@Scheduled(fixedRate = 1000)
public
void
heartbeat
()
{
public
void
heartbeat
()
{
String
body
=
String
.
format
(
"%02x"
,
Constants
.
COMMAND_HEARTBEAT
.
length
()
/
2
).
concat
(
Constants
.
COMMAND_HEARTBEAT
);
String
body
=
String
.
format
(
"%02x"
,
Constants
.
COMMAND_HEARTBEAT
.
length
()
/
2
).
concat
(
Constants
.
COMMAND_HEARTBEAT
);
String
crc16HexStr
=
CRC16Utils
.
getCRC16HexStr
(
body
);
String
crc16HexStr
=
CRC16Utils
.
getCRC16HexStr
(
body
);
...
...
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