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
94fe404f
Commit
94fe404f
authored
Dec 02, 2022
by
zhushanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket和tcpsocket
parent
8cedea05
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
40 deletions
+0
-40
TcpServer.java
src/main/java/server/TcpServer.java
+0
-40
No files found.
src/main/java/server/TcpServer.java
View file @
94fe404f
...
...
@@ -34,10 +34,6 @@ public class TcpServer {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TcpServer
.
class
);
// 服务器地址端口
// private static final String IP = "192.168.0.112";
// private static final String IP = "192.168.0.107";
// public static String IP = "8.143.203.103";
private
static
final
int
PORT
=
9095
;
...
...
@@ -61,46 +57,10 @@ public class TcpServer {
ServerBootstrap
b
=
new
ServerBootstrap
();
b
.
group
(
bossGroup
,
workerGroup
);
b
.
channel
(
NioServerSocketChannel
.
class
);
// b.childOption(ChannelOption.SO_REUSEADDR, true); //快速复用端口
// b.childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS,1000);
b
.
childHandler
(
new
ChannelInitializer
<
SocketChannel
>()
{
@Override
public
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
// ChannelPipeline pipeline = ch.pipeline();
// Decode是对发送的信息进行编码、
// @param maxFrameLength 帧的最大长度
// @param lengthFieldOffset length字段偏移的地址
// @param lengthFieldLength length字段所占的字节
// @param lengthAdjustment 修改帧数据长度字段中定义的值,
// 可以为负数 因为有时候我们习惯把头部记入长度,若为负数,则说明要推后多少个字段
// @param initialBytesToStrip 解析时候跳过多少个长度
// pipeline.addLast(new StringEncoder());
// pipeline.addLast(new StringDecoder());
// pipeline.addLast(new TcpServerHandler());
//因为基于http协议,使用http的编码和解码器
// pipeline.addLast(new HttpServerCodec());
// //是以块方式写,添加ChunkedWriteHandler处理器
// pipeline.addLast(new ChunkedWriteHandler());
// // http数据聚合器 用于将大数据量分段传输的数据 聚合
// pipeline.addLast(new HttpObjectAggregator(8192));
// // websocket协议处理器
// pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
// // 自定义的业务处理
// pipeline.addLast(new TcpServerHandler());
// ch.pipeline().addLast("active",new ChannelActiveHandler() );
// //Socket 连接心跳检测
// ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(60, 0, 0));
//
// ch.pipeline().addLast("socketChoose",new SocketChooseHandler());
//
// //注意,这个专门针对 Socket 信息的解码器只能放在 SocketChooseHandler 之后,否则会导致 webSocket 连接出错
// ch.pipeline().addLast("myDecoder",new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN,1024*1024,0,4,0,4,true));
// ch.pipeline().addLast("commonhandler",new DeviceServerHandler());
ch
.
pipeline
().
addLast
(
"socketChoose"
,
new
SocketChooseHandler
());
ch
.
pipeline
().
addLast
(
new
StringDecoder
(
CharsetUtil
.
UTF_8
));
ch
.
pipeline
().
addLast
(
new
StringEncoder
(
CharsetUtil
.
UTF_8
));
...
...
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