Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
GnssServer
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
zhushanglei
GnssServer
Commits
538382b3
Commit
538382b3
authored
May 06, 2022
by
zhushanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gps服务分开,服务端,客户端
parent
c9863a30
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
21 deletions
+10
-21
TcpClient.java
src/main/java/client/TcpClient.java
+7
-0
TcpClientHandler.java
src/main/java/client/TcpClientHandler.java
+2
-1
TcpServer.java
src/main/java/server/TcpServer.java
+1
-20
No files found.
src/main/java/client/TcpClient.java
View file @
538382b3
...
@@ -12,6 +12,7 @@ import server.TcpServer;
...
@@ -12,6 +12,7 @@ import server.TcpServer;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.net.InetAddress
;
import
java.util.Properties
;
import
java.util.Properties
;
/**
/**
...
@@ -23,6 +24,7 @@ public class TcpClient {
...
@@ -23,6 +24,7 @@ public class TcpClient {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServer
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServer
.
class
);
public
static
String
HOST
;
public
static
String
HOST
;
public
static
String
PORT
;
public
static
String
PORT
;
public
static
String
deviceId
;
static
{
static
{
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
"config.properties"
);
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
"config.properties"
);
...
@@ -92,6 +94,11 @@ public class TcpClient {
...
@@ -92,6 +94,11 @@ public class TcpClient {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
try
{
try
{
InetAddress
addr
=
InetAddress
.
getLocalHost
();
logger
.
info
(
"Local HostAddress:"
+
addr
.
getHostAddress
());
String
hostname
=
addr
.
getHostName
();
deviceId
=
hostname
;
logger
.
info
(
"Local host name: "
+
hostname
);
Properties
config
=
new
Properties
();
Properties
config
=
new
Properties
();
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
"config.properties"
);
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
"config.properties"
);
config
.
load
(
in
);
config
.
load
(
in
);
...
...
src/main/java/client/TcpClientHandler.java
View file @
538382b3
...
@@ -36,6 +36,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -36,6 +36,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
if
(
null
==
result
){
if
(
null
==
result
){
openComm
();
openComm
();
}
}
Thread
.
sleep
(
5000
);
logger
.
info
(
"**COM口读出数据<<start:"
+
result
+
">>end"
);
logger
.
info
(
"**COM口读出数据<<start:"
+
result
+
">>end"
);
sendGnss
(
result
);
sendGnss
(
result
);
}
}
...
@@ -66,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -66,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
simplePoint
.
setX
(
x
);
simplePoint
.
setX
(
x
);
simplePoint
.
setY
(
y
);
simplePoint
.
setY
(
y
);
gpsDto
.
setName
(
Tcp
Server
.
deviceId
);
gpsDto
.
setName
(
Tcp
Client
.
deviceId
);
gpsDto
.
setTime
(
new
Date
());
gpsDto
.
setTime
(
new
Date
());
gpsDto
.
setLocation
(
simplePoint
);
gpsDto
.
setLocation
(
simplePoint
);
...
...
src/main/java/server/TcpServer.java
View file @
538382b3
...
@@ -31,7 +31,7 @@ public class TcpServer {
...
@@ -31,7 +31,7 @@ public class TcpServer {
public
static
String
IP
=
"127.0.0.1"
;
public
static
String
IP
=
"127.0.0.1"
;
private
static
final
int
PORT
=
9200
;
private
static
final
int
PORT
=
9200
;
public
static
String
deviceId
;
/** 用于分配处理业务线程的线程组个数 */
/** 用于分配处理业务线程的线程组个数 */
protected
static
final
int
BIZGROUPSIZE
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
protected
static
final
int
BIZGROUPSIZE
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
...
@@ -70,25 +70,6 @@ public class TcpServer {
...
@@ -70,25 +70,6 @@ public class TcpServer {
}
}
});
});
// 异步绑定端口
// 异步绑定端口
InetAddress
addr
=
InetAddress
.
getLocalHost
();
logger
.
info
(
"Local HostAddress:"
+
addr
.
getHostAddress
());
String
hostname
=
addr
.
getHostName
();
// byte[] mac = NetworkInterface.getByInetAddress(addr).getHardwareAddress();
//
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < mac.length; i++) {
// if (i != 0) {
// sb.append("-");
// }
// // mac[i] & 0xFF 是为了把byte转化为正整数
// String s = Integer.toHexString(mac[i] & 0xFF);
// sb.append(s.length() == 1 ? 0 + s : s);
// }
// deviceId = sb.toString();
// logger.info("mac: "+sb.toString());
deviceId
=
hostname
;
logger
.
info
(
"Local host name: "
+
hostname
);
// b.bind(addr.getHostAddress(), PORT).sync();
b
.
bind
(
IP
,
PORT
).
sync
();
b
.
bind
(
IP
,
PORT
).
sync
();
logger
.
info
(
"TCP Server Started"
);
logger
.
info
(
"TCP Server Started"
);
}
}
...
...
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