Commit cc86d1bc authored by zhushanglei's avatar zhushanglei

init

parent 697b5cd5
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();
}
} }
...@@ -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");
private static final String serverUrl = "http://192.168.0.107:8001/gps"; public 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口未打开");
......
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