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
cc86d1bc
Commit
cc86d1bc
authored
Apr 06, 2022
by
zhushanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
697b5cd5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
TcpServer.java
src/main/java/server/TcpServer.java
+13
-6
TcpServerHandler.java
src/main/java/server/TcpServerHandler.java
+5
-1
No files found.
src/main/java/server/TcpServer.java
View file @
cc86d1bc
package
server
;
package
server
;
import
com.sun.org.apache.regexp.internal.RE
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.bootstrap.ServerBootstrap
;
import
io.netty.channel.ChannelInitializer
;
import
io.netty.channel.ChannelInitializer
;
import
io.netty.channel.ChannelPipeline
;
import
io.netty.channel.ChannelPipeline
;
...
@@ -15,8 +16,13 @@ import io.netty.util.CharsetUtil;
...
@@ -15,8 +16,13 @@ import io.netty.util.CharsetUtil;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.NetworkInterface
;
import
java.util.Properties
;
/**
/**
* @author yuli
* @author yuli
...
@@ -29,7 +35,7 @@ public class TcpServer {
...
@@ -29,7 +35,7 @@ public class TcpServer {
// 服务器地址端口
// 服务器地址端口
// private static final String IP = "192.168.0.112";
// private static final String IP = "192.168.0.112";
private
static
final
String
IP
=
"192.168.0.107"
;
//
private static final String IP = "192.168.0.107";
private
static
final
int
PORT
=
9200
;
private
static
final
int
PORT
=
9200
;
public
static
String
deviceId
;
public
static
String
deviceId
;
...
@@ -96,18 +102,19 @@ public class TcpServer {
...
@@ -96,18 +102,19 @@ public class TcpServer {
}
}
// 关闭端口
// 关闭端口
protected
static
void
shutdown
()
{
protected
static
void
shutdown
()
{
TcpServerHandler
.
closeComm
();
workerGroup
.
shutdownGracefully
();
workerGroup
.
shutdownGracefully
();
bossGroup
.
shutdownGracefully
();
bossGroup
.
shutdownGracefully
();
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
logger
.
info
(
"Starting TCP Server..."
);
logger
.
info
(
"Starting TCP Server..."
);
Properties
config
=
new
Properties
();
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
"config.properties"
);
config
.
load
(
in
);
TcpServerHandler
.
serverUrl
=
config
.
getProperty
(
"serverUrl"
);
logger
.
info
(
"后端接口>>"
+
TcpServerHandler
.
serverUrl
);
TcpServer
.
run
();
TcpServer
.
run
();
// TcpServer.shutdown();
// TcpServer.shutdown();
}
}
@Override
protected
void
finalize
()
throws
Throwable
{
super
.
finalize
();
}
}
}
src/main/java/server/TcpServerHandler.java
View file @
cc86d1bc
...
@@ -20,7 +20,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -20,7 +20,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServerHandler
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServerHandler
.
class
);
// public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
// public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
p
rivate
static
final
String
serverUrl
=
"http://192.168.0.107:8001/gps"
;
p
ublic
static
String
serverUrl
;
/**
/**
* 打印接收到的内容,并回传
* 打印接收到的内容,并回传
// * @param [ctx, msg]
// * @param [ctx, msg]
...
@@ -136,6 +136,10 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -136,6 +136,10 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
return
serialPort
;
return
serialPort
;
}
}
public
static
void
closeComm
(){
if
(
null
!=
serialPort
)
serialPort
.
closePort
();
}
private
int
writeComm
(
SerialPort
serialPort
,
byte
[]
data
)
throws
InterruptedException
{
private
int
writeComm
(
SerialPort
serialPort
,
byte
[]
data
)
throws
InterruptedException
{
if
(
serialPort
==
null
||
!
serialPort
.
isOpen
()){
if
(
serialPort
==
null
||
!
serialPort
.
isOpen
()){
logger
.
info
(
"COM口未打开"
);
logger
.
info
(
"COM口未打开"
);
...
...
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