Commit 538382b3 authored by zhushanglei's avatar zhushanglei

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

parent c9863a30
...@@ -12,6 +12,7 @@ import server.TcpServer; ...@@ -12,6 +12,7 @@ import server.TcpServer;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress;
import java.util.Properties; import java.util.Properties;
/** /**
...@@ -23,6 +24,7 @@ public class TcpClient { ...@@ -23,6 +24,7 @@ public class TcpClient {
private static Logger logger = LoggerFactory.getLogger(TcpServer.class); private static Logger logger = LoggerFactory.getLogger(TcpServer.class);
public static String HOST; public static String HOST;
public static String PORT; public static String PORT;
public static String deviceId ;
static { static {
InputStream in = ClassLoader.getSystemResourceAsStream("config.properties"); InputStream in = ClassLoader.getSystemResourceAsStream("config.properties");
...@@ -92,6 +94,11 @@ public class TcpClient { ...@@ -92,6 +94,11 @@ public class TcpClient {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
try { 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(); Properties config = new Properties();
InputStream in = ClassLoader.getSystemResourceAsStream("config.properties"); InputStream in = ClassLoader.getSystemResourceAsStream("config.properties");
config.load(in); config.load(in);
......
...@@ -36,6 +36,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> { ...@@ -36,6 +36,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
if(null == result){ if(null == result){
openComm(); openComm();
} }
Thread.sleep(5000);
logger.info("**COM口读出数据<<start:" + result +">>end"); logger.info("**COM口读出数据<<start:" + result +">>end");
sendGnss(result); sendGnss(result);
} }
...@@ -66,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> { ...@@ -66,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {
simplePoint.setX(x); simplePoint.setX(x);
simplePoint.setY(y); simplePoint.setY(y);
gpsDto.setName(TcpServer.deviceId); gpsDto.setName(TcpClient.deviceId);
gpsDto.setTime(new Date()); gpsDto.setTime(new Date());
gpsDto.setLocation(simplePoint); gpsDto.setLocation(simplePoint);
......
...@@ -31,7 +31,7 @@ public class TcpServer { ...@@ -31,7 +31,7 @@ public class TcpServer {
public static String IP = "127.0.0.1"; public static String IP = "127.0.0.1";
private static final int PORT = 9200; private static final int PORT = 9200;
public static String deviceId ;
/** 用于分配处理业务线程的线程组个数 */ /** 用于分配处理业务线程的线程组个数 */
protected static final int BIZGROUPSIZE = Runtime.getRuntime().availableProcessors() * 2; protected static final int BIZGROUPSIZE = Runtime.getRuntime().availableProcessors() * 2;
...@@ -70,25 +70,6 @@ public class TcpServer { ...@@ -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(); b.bind(IP, PORT).sync();
logger.info("TCP Server Started"); 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