1、增加两路推送功能,推送本地和推送老服务器
This commit is contained in:
parent
dc1813630d
commit
e05e5092e4
@ -0,0 +1,24 @@
|
||||
package com.imdroid.ntripproxy.service;
|
||||
|
||||
public class Ntrip2Channels {
|
||||
final private String localHost="127.0.0.1";
|
||||
final private int localPort=9903;
|
||||
final private String remoteHost="47.107.50.52";
|
||||
final private int remotePort=9903;
|
||||
|
||||
public static final Ntrip2Channels INSTANCE = new Ntrip2Channels();
|
||||
|
||||
UDPClient localRtcm;
|
||||
UDPClient remoteRtcm;
|
||||
private Ntrip2Channels() {
|
||||
localRtcm = new UDPClient();
|
||||
remoteRtcm = new UDPClient();
|
||||
localRtcm.init(localHost, localPort);
|
||||
remoteRtcm.init(remoteHost, remotePort);
|
||||
}
|
||||
|
||||
public void send(byte[] data) {
|
||||
localRtcm.send(data);
|
||||
remoteRtcm.send(data);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.imdroid.ntripproxy.service;
|
||||
|
||||
import com.imdroid.common.util.DataTypeUtil;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Layton
|
||||
* @date 2023/2/13 11:47
|
||||
*/
|
||||
@ChannelHandler.Sharable
|
||||
@Component
|
||||
public class UdpHandler2 extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UdpHandler2.class);
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
DatagramPacket packet = (DatagramPacket) msg;
|
||||
try {
|
||||
if (packet.content() == null) {
|
||||
return;
|
||||
}
|
||||
byte[] data = new byte[packet.content().readableBytes()];
|
||||
packet.content().getBytes(0, data);
|
||||
Ntrip2Channels.INSTANCE.send(data);
|
||||
logger.debug("receive message:" + DataTypeUtil.getHexString(data));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("channel read error: {}", e.toString());
|
||||
} finally {
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
logger.error("Exception caught: {}", cause.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.imdroid.ntripproxy.service;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Layton
|
||||
* @date 2023/2/13 11:47
|
||||
*/
|
||||
@Component
|
||||
public class UdpServer2 implements ApplicationRunner {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(UdpServer2.class);
|
||||
|
||||
@Value("${ntrip.proxy2.port}")
|
||||
private Integer port;
|
||||
|
||||
@Autowired
|
||||
private UdpHandler2 udpHandler;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
new Thread(this::start0, "ntrip2-proxy").start();
|
||||
}
|
||||
|
||||
private void start0() {
|
||||
EventLoopGroup group = new NioEventLoopGroup();
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioDatagramChannel.class)
|
||||
.option(ChannelOption.SO_SNDBUF, 1024*1024) //1M缓存,考虑1000个基站同时转发
|
||||
.option(ChannelOption.SO_RCVBUF, 1024*1024)//1M缓存,断点续传要大带宽
|
||||
.handler(udpHandler);
|
||||
try {
|
||||
ChannelFuture future = bootstrap.bind(port).sync().channel().closeFuture();
|
||||
logger.info("ntrip2 proxy start at port {}", port);
|
||||
future.await();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error starting Imdroid protocol at port {}", port, e);
|
||||
} finally {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,5 +15,11 @@ ntrip.proxy.port = 11001
|
||||
ntrip.server.host = 47.107.50.52
|
||||
ntrip.server.port = 11003
|
||||
|
||||
ntrip.proxy2.port = 11002
|
||||
ntrip.server2.host = 47.107.50.52
|
||||
ntrip.server2.port = 9903
|
||||
#ntrip.server2.host = 127.0.0.1
|
||||
#ntrip.server2.port = 9913
|
||||
|
||||
rtcm.server.host = 127.0.0.1
|
||||
rtcm.server.port = 9903
|
||||
rtcm.server.port = 9903
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user