Commit b304dbc0 authored by zhushanglei's avatar zhushanglei

gps数据采集修改

parent 538382b3
......@@ -28,8 +28,8 @@ public class TcpServer {
// 服务器地址端口
// private static final String IP = "192.168.0.112";
// private static final String IP = "192.168.0.107";
public static String IP = "127.0.0.1";
private static final int PORT = 9200;
// public static String IP = "8.143.203.103";
private static final int PORT = 9093;
......@@ -70,7 +70,7 @@ public class TcpServer {
}
});
// 异步绑定端口
b.bind(IP, PORT).sync();
b.bind(PORT).sync();
logger.info("TCP Server Started");
}
// 关闭端口
......
......@@ -30,7 +30,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
// public static String serverUrl;
//全局变量
Map<String, ChannelHandlerContext> gpsServerContextHashMap = new HashMap<>();
private static Map<String, ChannelHandlerContext> gpsServerContextHashMap = new HashMap<>();
//获取全局变量信息
public ChannelHandlerContext getContext(String key){
return gpsServerContextHashMap.get(key);
......@@ -53,11 +53,16 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
// logger.info("**接收到的基站数据<<start:" + msg.toString() +">>end");
if(TcpClient.client.equalsIgnoreCase(msg.toString())){ //移动站
String clinetIp = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();
String clinetIp = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress() + ctx.channel().id();
logger.warn("移动站IP:" + clinetIp);
addContext(clinetIp,ctx);
// ctx.writeAndFlush("你好"); //TextWebSocketFrame
logger.warn("if>>hashmap移动站:" + gpsServerContextHashMap);
ctx.writeAndFlush("OK!!"); //TextWebSocketFrame
}else{ //基站
logger.info("else>>基站:" + msg.toString());
logger.info("else>>hashmap基站:" + gpsServerContextHashMap);
gpsServerContextHashMap.forEach((k,v)->{
logger.error("基站发送给移动站:" + msg.toString());
v.writeAndFlush(msg.toString());
});
}
......
serverUrl:http://192.168.0.111:8001/gps
gpsServerIP:127.0.0.1
gpsServerPort:9200
\ No newline at end of file
serverUrl:http://8.143.203.103:9090/gps
gpsServerIP:8.143.203.103
gpsServerPort:9093
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment