Commit 538382b3 authored by zhushanglei's avatar zhushanglei

gps服务分开,服务端,客户端

parent c9863a30
......@@ -12,6 +12,7 @@ import server.TcpServer;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.Properties;
/**
......@@ -23,6 +24,7 @@ public class TcpClient {
private static Logger logger = LoggerFactory.getLogger(TcpServer.class);
public static String HOST;
public static String PORT;
public static String deviceId ;
static {
InputStream in = ClassLoader.getSystemResourceAsStream("config.properties");
......@@ -92,6 +94,11 @@ public class TcpClient {
public static void main(String[] args) throws Exception {
try {
InetAddress addr = InetAddress.getLocalHost();
logger.info("Local HostAddress:"+addr.getHostAddress());
String hostname = addr.getHostName();
deviceId = hostname;
logger.info("Local host name: "+hostname);
Properties config = new Properties();
InputStream in = ClassLoader.getSystemResourceAsStream("config.properties");
config.load(in);
......
......@@ -36,6 +36,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
if(null == result){
openComm();
}
Thread.sleep(5000);
logger.info("**COM口读出数据<<start:" + result +">>end");
sendGnss(result);
}
......@@ -66,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
simplePoint.setX(x);
simplePoint.setY(y);
gpsDto.setName(TcpServer.deviceId);
gpsDto.setName(TcpClient.deviceId);
gpsDto.setTime(new Date());
gpsDto.setLocation(simplePoint);
......
......@@ -31,7 +31,7 @@ public class TcpServer {
public static String IP = "127.0.0.1";
private static final int PORT = 9200;
public static String deviceId ;
/** 用于分配处理业务线程的线程组个数 */
protected static final int BIZGROUPSIZE = Runtime.getRuntime().availableProcessors() * 2;
......@@ -70,25 +70,6 @@ public class TcpServer {
}
});
// 异步绑定端口
InetAddress addr = InetAddress.getLocalHost();
logger.info("Local HostAddress:"+addr.getHostAddress());
String hostname = addr.getHostName();
// byte[] mac = NetworkInterface.getByInetAddress(addr).getHardwareAddress();
//
// StringBuffer sb = new StringBuffer();
// for (int i = 0; i < mac.length; i++) {
// if (i != 0) {
// sb.append("-");
// }
// // mac[i] & 0xFF 是为了把byte转化为正整数
// String s = Integer.toHexString(mac[i] & 0xFF);
// sb.append(s.length() == 1 ? 0 + s : s);
// }
// deviceId = sb.toString();
// logger.info("mac: "+sb.toString());
deviceId = hostname;
logger.info("Local host name: "+hostname);
// b.bind(addr.getHostAddress(), PORT).sync();
b.bind(IP, PORT).sync();
logger.info("TCP Server Started");
}
......
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