a
554325746@qq.com
2019-12-25 38492bbaa63586e2f4877da0eaa01a082fd565a6
app/src/main/java/com/basic/security/utils/SocketClient.java
@@ -13,12 +13,9 @@
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import org.json.JSONArray;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -28,9 +25,31 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class SocketClient extends Thread {
    Socket socket;
    public static boolean needRestart = false;
    public static long lastUpdateTime = System.currentTimeMillis();
    static Lock socketLock = new ReentrantLock();
    static List<Socket> sockets = new ArrayList<>();
    static List<Socket> connectedSockets = new ArrayList<>();
    static Lock connectedSocketsLock = new ReentrantLock();
    public static Comparator<Map<String, String>> mapComparator = new Comparator<Map<String, String>>() {
        public int compare(Map<String, String> m1, Map<String, String> m2) {
            try {
                double score1 = Double.parseDouble(m1.get("likePer"));
                double score2 = Double.parseDouble(m2.get("likePer"));
                return (int) (score1 - score2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        }
    };
    public Socket socket = null;
    static List<Map<String, String>> newRemoteAlarmList = null;
    byte[] buff = new byte[1 * 1024 * 1024];
    private String ip;
    private int port;
@@ -39,22 +58,32 @@
        this.port = port;
    }
    public static boolean needRestart = false;
    public Comparator<Map<String, String>> mapComparator = new Comparator<Map<String, String>>() {
        public int compare(Map<String, String> m1, Map<String, String> m2) {
    public static void closeAllSockets() {
        socketLock.lock();
        for (Socket socket : sockets) {
            try {
                double score1 = Double.parseDouble(m1.get("likePer"));
                double score2 = Double.parseDouble(m2.get("likePer"));
                return (int)(score1 - score2);
                if (socket != null) {
                    socket.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        }
    };
        sockets.clear();
        socketLock.unlock();
    }
    public void parseJson(String msg) {
    public static void socketAdd(Socket socket) {
        socketLock.lock();
        sockets.add(socket);
        socketLock.unlock();
    }
    public native void setup(String ip, int port);
    public native String receive();
    public static void parseJson(String msg) {
        JsonParser parser = new JsonParser();
        boolean isJSON = true;
@@ -62,7 +91,7 @@
        try {
            element = parser.parse(msg);
        } catch (JsonParseException e) {
            System.out.println("exception: "+ msg + " " + e);
            System.out.println("exception: " + msg + " " + e);
            isJSON = false;
        }
        newRemoteAlarmList = new ArrayList<>();
@@ -70,9 +99,9 @@
            Object obj = element.getAsJsonObject();
            JsonArray dataList = (JsonArray) ((JsonObject) obj).get("datalist");
            for (int i = 0; i < dataList.size(); i++) {
                JsonObject je = (JsonObject)dataList.get(i);
                JsonObject je = (JsonObject) dataList.get(i);
                Map<String, String> newRemoteAlarm = new HashMap<>();
                for(Map.Entry<String, JsonElement> entry : je.entrySet()) {
                for (Map.Entry<String, JsonElement> entry : je.entrySet()) {
                    Object value = entry.getValue();
                    String key = entry.getKey();
                    if (value != null) {
@@ -81,12 +110,12 @@
                            List<String> matchPersonStrList = new ArrayList<>();
                            String matchPersonListStr = "";
                            if (value instanceof JsonArray) {
                                JsonArray matchPersonList = (JsonArray)value;
                                for (int ii = 0; ii < matchPersonList.size(); ii++ ) {
                                    JsonObject matchPerson = (JsonObject)matchPersonList.get(ii);
                                JsonArray matchPersonList = (JsonArray) value;
                                for (int ii = 0; ii < matchPersonList.size(); ii++) {
                                    JsonObject matchPerson = (JsonObject) matchPersonList.get(ii);
                                    Map<String, String> matchPersonMap = new HashMap<>();
                                    for(Map.Entry<String, JsonElement> matchPersonEntry : matchPerson.entrySet()) {
                                    for (Map.Entry<String, JsonElement> matchPersonEntry : matchPerson.entrySet()) {
                                        String matchPersonKey = matchPersonEntry.getKey();
                                        Object matchPersonValue = matchPersonEntry.getValue();
                                        if (matchPersonValue != null) {
@@ -102,7 +131,7 @@
                                            matchPersonMap.put(matchPersonKey, "");
                                        }
                                    }
                                    matchPersonMap.put("mathPersonStr",  matchPersonMap.get("tableName")+ " " +  matchPersonMap.get("personName"));
                                    matchPersonMap.put("mathPersonStr", matchPersonMap.get("tableName") + " " + matchPersonMap.get("personName"));
                                    matchPersonMapList.add(matchPersonMap);
                                }
                                Collections.sort(matchPersonMapList, mapComparator);
@@ -127,79 +156,135 @@
//                                        }
                AlarmManager.renameKeys(newRemoteAlarmList);
                if (AlarmManager.saveRemoteAlarmListToSqlite(newRemoteAlarmList) > 0) {
                    ((MainActivity)BaseApplication.getApplication().activity).fragment_home.refreshGridView();
                    ((MainActivity) BaseApplication.getApplication().activity).fragment_home.refreshGridView();
                }
            } else {
                if (((MainActivity)BaseApplication.getApplication().activity).currentFragment ==
                        ((MainActivity)BaseApplication.getApplication().activity).fragment_home) {
                if (((MainActivity) BaseApplication.getApplication().activity).currentFragment ==
                        ((MainActivity) BaseApplication.getApplication().activity).fragment_home) {
                    ToastUtil.show("获取报警数据失败");
                }
            }
        }
    }
    List<Map<String, String>> newRemoteAlarmList = null;
    @Override
    public void run() {
        super.run();
        BufferedInputStream inputStream = null;
        BufferedOutputStream outputStream = null;
        Socket socket = null;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        String msg = null;
        try {
            while (true) {
                try {
                    if (1!=1) {
                        msg = "{ \t\"datalist\": [ \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"8a769d1c-886c-487c-a934-e92b09d8f189\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段中向东     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:26\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6n2AFGElABQIY3pylXU412.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段中向东     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid3\" \t\t}, \t\t{ \t\t\t\"ID\": \"68a6fe5c-1cb1-4e3c-bc4a-22d678f76e8d\", \t\t\t\"IDCard\": [ \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\", \t\t\t\t\"54319001310104514563\", \t\t\t\t\"54319001100121231977\", \t\t\t\t\"54319001202319872643\", \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\" \t\t\t], \t\t\t\"ageDescription\": \"青年\", \t\t\t\"baseInfo\": [ \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"43\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"80a5935d-c6b4-4678-9c76-a6b01c07725b\", \t\t\t\t\t\"tableName\": \"底库124\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"41\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"5a544e15-2c40-4e54-a12b-f6a0f71f3fbd\", \t\t\t\t\t\"tableName\": \"底库123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001310104514563\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"78\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"83a42f98-ad21-466f-97aa-24bff1b0340f\", \t\t\t\t\t\"personName\": \"黄飞鸿\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbb19faece3\", \t\t\t\t\t\"phoneNum\": \"11067854653\", \t\t\t\t\t\"tableId\": \"0cb7f275-9fb3-434e-9122-e59f551443ea\", \t\t\t\t\t\"tableName\": \"底库123412\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001100121231977\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"20\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"fed7b71c-d5eb-4feb-86d9-0522d7034412\", \t\t\t\t\t\"personName\": \"李逍遥\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/11,06dfb71c698169\", \t\t\t\t\t\"phoneNum\": \"11012344321\", \t\t\t\t\t\"tableId\": \"f008bf89-9406-490d-868b-6dd679cae954\", \t\t\t\t\t\"tableName\": \"同步库2\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"40\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"ce228150-448b-4e70-9b08-374ed7c5bc3e\", \t\t\t\t\t\"tableName\": \"123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"86\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"af6dd3b3-dc94-42ee-8347-f12214c2562f\", \t\t\t\t\t\"tableName\": \"同步库3\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"66\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"2e0640d0-33e5-45e6-b024-3fe165c6f9e9\", \t\t\t\t\t\"tableName\": \"测试底库名称超长字数测试\" \t\t\t\t} \t\t\t], \t\t\t\"content\": \"\", \t\t\t\"gender\": \"男\", \t\t\t\"id\": \"68a6fe5c-1cb1-4e3c-bc4a-22d678f76e8d\", \t\t\t\"indeviceName\": \"视频分析设备244\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"测试地址\", \t\t\t\"picDate\": \"2019-05-17 12:19:21\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/6A/rBEy8VzbhTaABvYpAAgn7hKYC2g311.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group2/M00/00/B4/rBEy9Fx1Bn2ASQ6FAABDPo9CwFw073.jpg\", \t\t\t\"race\": \"黄人\", \t\t\t\"sdkType\": \"人脸\", \t\t\t\"taskName\": \"run\", \t\t\t\"videoIp\": \"172.17.50.244\", \t\t\t\"videoNum\": \"http://192.168.1.203:9600/12,017dae9d21ac08\", \t\t\t\"videoReqNum\": \"cid3\" \t\t}, \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"fea3e88f-a2c4-4a07-a19d-89c336f446ee\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段东向西     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:21\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6Y-AORXtABZqoERSp9I640.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段东向西     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid2\" \t\t}, \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"5fa82d38-b725-45dc-907e-a7ee0ad3e803\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段东向西     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:16\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6Y2AHleCABVr-OZBNps388.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段东向西     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid1\" \t\t}, \t\t{ \t\t\t\"ID\": \"3bce3eef-2062-456e-b5cb-d1a4cc63c158\", \t\t\t\"IDCard\": [ \t\t\t\t\"54319001202319872643\", \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\", \t\t\t\t\"54319001310104514563\", \t\t\t\t\"54319001100121231977\", \t\t\t\t\"54319001202319872643\" \t\t\t], \t\t\t\"ageDescription\": \"青年\", \t\t\t\"baseInfo\": [ \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"3\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"2e0640d0-33e5-45e6-b024-3fe165c6f9e9\", \t\t\t\t\t\"tableName\": \"测试底库名称超长字数测试\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"31\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"80a5935d-c6b4-4678-9c76-a6b01c07725b\", \t\t\t\t\t\"tableName\": \"底库124\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"1\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"5a544e15-2c40-4e54-a12b-f6a0f71f3fbd\", \t\t\t\t\t\"tableName\": \"底库123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001310104514563\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"1\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"83a42f98-ad21-466f-97aa-24bff1b0340f\", \t\t\t\t\t\"personName\": \"黄飞鸿\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbb19faece3\", \t\t\t\t\t\"phoneNum\": \"11067854653\", \t\t\t\t\t\"tableId\": \"0cb7f275-9fb3-434e-9122-e59f551443ea\", \t\t\t\t\t\"tableName\": \"底库123412\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001100121231977\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"48\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"fed7b71c-d5eb-4feb-86d9-0522d7034412\", \t\t\t\t\t\"personName\": \"李逍遥\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/11,06dfb71c698169\", \t\t\t\t\t\"phoneNum\": \"11012344321\", \t\t\t\t\t\"tableId\": \"f008bf89-9406-490d-868b-6dd679cae954\", \t\t\t\t\t\"tableName\": \"同步库2\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"97\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"ce228150-448b-4e70-9b08-374ed7c5bc3e\", \t\t\t\t\t\"tableName\": \"123\" \t\t\t\t} \t\t\t], \t\t\t\"content\": \"\", \t\t\t\"gender\": \"男\", \t\t\t\"id\": \"3bce3eef-2062-456e-b5cb-d1a4cc63c158\", \t\t\t\"indeviceName\": \"视频分析设备244\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"测试地址\", \t\t\t\"picDate\": \"2019-05-17 12:19:16\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/6A/rBEy8VzbhTaABvYpAAgn7hKYC2g311.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group2/M00/00/B4/rBEy9Fx1Bn-AS7idAAAgkMt8drY443.jpg\", \t\t\t\"race\": \"黑人\", \t\t\t\"sdkType\": \"人脸\", \t\t\t\"taskName\": \"face\", \t\t\t\"videoIp\": \"172.17.50.244\", \t\t\t\"videoNum\": \"http://192.168.1.203:9600/12,017dae9d21ac08\", \t\t\t\"videoReqNum\": \"cid2\" \t\t} \t], \t\"total\": 5 }";
                        parseJson(msg);
                        SystemClock.sleep(2000);
                        continue;
                    }
                    ip = SettingManager.getIpStr();
                    port = SettingManager.getPort();
                    socket = new Socket();
                    socket.connect(new InetSocketAddress(ip, port), 3000);
//                    socket.connect(new InetSocketAddress(ip, 7000), 3000);
                    inputStream = new BufferedInputStream(socket.getInputStream());
                    outputStream = new BufferedOutputStream(socket.getOutputStream());
                    byte[] buff = new byte[10*1024*1024];
                    int len = 0;
                    while ((len = inputStream.read(buff)) != -1) {
                        for (int i1 = 0; i1 <len; i1++) {
                            if (buff[i1] == '\0') {
                                byte[] msgBuf = byteArrayOutputStream.toByteArray();
                                msg = new String(msgBuf, 0, msgBuf.length);
                                msg = msg.substring(0, msg.lastIndexOf("}") + 1);
                                byteArrayOutputStream.reset();
                                System.out.println("msg="+msg);
                                parseJson(msg);
                            } else {
                                byteArrayOutputStream.write(buff[i1]);
                            }
                        }
                        if (needRestart) {
                            needRestart = false;
                            break;
                        }
                    }
                } catch (Exception e) {
                    System.out.println("SocketClient:110, " + e.getMessage());
                } finally {
                    if (socket != null) {
                if (1 != 1) {
                    System.out.println("SocketClient.run setup 重连");
                    setup(ip, port);
                    while (true) {
                        try {
                            socket.close();
                            String json = receive();
                            System.out.println("json=" + json);
                            lastUpdateTime = System.currentTimeMillis();
                            if (json.length() > 0) {
                                if (json.equals("-1")) {
                                    System.out.println("SocketClient.run setup 错误");
                                    SystemClock.sleep(100);
                                    break;
                                }
                                parseJson(json);
                            } else {
                                SystemClock.sleep(100);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    SystemClock.sleep(2000);
                    SystemClock.sleep(1000);
//                    continue;
                } else {
                    try {
                        if (1 != 1) {
                            msg = "{ \t\"datalist\": [ \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"8a769d1c-886c-487c-a934-e92b09d8f189\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段中向东     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:26\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6n2AFGElABQIY3pylXU412.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段中向东     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid3\" \t\t}, \t\t{ \t\t\t\"ID\": \"68a6fe5c-1cb1-4e3c-bc4a-22d678f76e8d\", \t\t\t\"IDCard\": [ \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\", \t\t\t\t\"54319001310104514563\", \t\t\t\t\"54319001100121231977\", \t\t\t\t\"54319001202319872643\", \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\" \t\t\t], \t\t\t\"ageDescription\": \"青年\", \t\t\t\"baseInfo\": [ \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"43\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"80a5935d-c6b4-4678-9c76-a6b01c07725b\", \t\t\t\t\t\"tableName\": \"底库124\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"41\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"5a544e15-2c40-4e54-a12b-f6a0f71f3fbd\", \t\t\t\t\t\"tableName\": \"底库123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001310104514563\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"78\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"83a42f98-ad21-466f-97aa-24bff1b0340f\", \t\t\t\t\t\"personName\": \"黄飞鸿\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbb19faece3\", \t\t\t\t\t\"phoneNum\": \"11067854653\", \t\t\t\t\t\"tableId\": \"0cb7f275-9fb3-434e-9122-e59f551443ea\", \t\t\t\t\t\"tableName\": \"底库123412\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001100121231977\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"20\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"fed7b71c-d5eb-4feb-86d9-0522d7034412\", \t\t\t\t\t\"personName\": \"李逍遥\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/11,06dfb71c698169\", \t\t\t\t\t\"phoneNum\": \"11012344321\", \t\t\t\t\t\"tableId\": \"f008bf89-9406-490d-868b-6dd679cae954\", \t\t\t\t\t\"tableName\": \"同步库2\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"40\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"ce228150-448b-4e70-9b08-374ed7c5bc3e\", \t\t\t\t\t\"tableName\": \"123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"86\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"af6dd3b3-dc94-42ee-8347-f12214c2562f\", \t\t\t\t\t\"tableName\": \"同步库3\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"66\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"2e0640d0-33e5-45e6-b024-3fe165c6f9e9\", \t\t\t\t\t\"tableName\": \"测试底库名称超长字数测试\" \t\t\t\t} \t\t\t], \t\t\t\"content\": \"\", \t\t\t\"gender\": \"男\", \t\t\t\"id\": \"68a6fe5c-1cb1-4e3c-bc4a-22d678f76e8d\", \t\t\t\"indeviceName\": \"视频分析设备244\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"测试地址\", \t\t\t\"picDate\": \"2019-05-17 12:19:21\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/6A/rBEy8VzbhTaABvYpAAgn7hKYC2g311.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group2/M00/00/B4/rBEy9Fx1Bn2ASQ6FAABDPo9CwFw073.jpg\", \t\t\t\"race\": \"黄人\", \t\t\t\"sdkType\": \"人脸\", \t\t\t\"taskName\": \"run\", \t\t\t\"videoIp\": \"172.17.50.244\", \t\t\t\"videoNum\": \"http://192.168.1.203:9600/12,017dae9d21ac08\", \t\t\t\"videoReqNum\": \"cid3\" \t\t}, \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"fea3e88f-a2c4-4a07-a19d-89c336f446ee\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段东向西     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:21\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6Y-AORXtABZqoERSp9I640.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段东向西     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid2\" \t\t}, \t\t{ \t\t\t\"content\": \"\", \t\t\t\"id\": \"5fa82d38-b725-45dc-907e-a7ee0ad3e803\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"学校南围墙西段东向西     周界\", \t\t\t\"picDate\": \"2019-05-17 12:19:16\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/4E/rBEy8VzbdN2AVqJIABGqRF1VFR0033.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group3/M00/05/18/rBEy81yy6Y2AHleCABVr-OZBNps388.jpg\", \t\t\t\"sdkType\": \"入侵\", \t\t\t\"taskName\": \"taskName刘欣\", \t\t\t\"videoIp\": \"学校南围墙西段东向西     周界\", \t\t\t\"videoNum\": \"http://58.118.225.79:44480/videosource/210235C23NF187000168/201905/15/2019051510/210235C23NF187000168$2019-05-15-10-09-37_454639_454888.mp4\", \t\t\t\"videoReqNum\": \"cid1\" \t\t}, \t\t{ \t\t\t\"ID\": \"3bce3eef-2062-456e-b5cb-d1a4cc63c158\", \t\t\t\"IDCard\": [ \t\t\t\t\"54319001202319872643\", \t\t\t\t\"54319001230310455431\", \t\t\t\t\"54319001102134569375\", \t\t\t\t\"54319001310104514563\", \t\t\t\t\"54319001100121231977\", \t\t\t\t\"54319001202319872643\" \t\t\t], \t\t\t\"ageDescription\": \"青年\", \t\t\t\"baseInfo\": [ \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"3\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"2e0640d0-33e5-45e6-b024-3fe165c6f9e9\", \t\t\t\t\t\"tableName\": \"测试底库名称超长字数测试\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001230310455431\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"31\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"70171c10-d8ba-4b7c-a7ec-94d4f89a8d7d\", \t\t\t\t\t\"personName\": \"石破天\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfb968957dfa\", \t\t\t\t\t\"phoneNum\": \"11093456217\", \t\t\t\t\t\"tableId\": \"80a5935d-c6b4-4678-9c76-a6b01c07725b\", \t\t\t\t\t\"tableName\": \"底库124\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001102134569375\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"1\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"68d89b3e-e4db-42eb-ac75-aa8c1082a087\", \t\t\t\t\t\"personName\": \"孙悟空\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbaa2516ad2\", \t\t\t\t\t\"phoneNum\": \"11031248765\", \t\t\t\t\t\"tableId\": \"5a544e15-2c40-4e54-a12b-f6a0f71f3fbd\", \t\t\t\t\t\"tableName\": \"底库123\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001310104514563\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"1\", \t\t\t\t\t\"monitorLevel\": \"1\", \t\t\t\t\t\"personId\": \"83a42f98-ad21-466f-97aa-24bff1b0340f\", \t\t\t\t\t\"personName\": \"黄飞鸿\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9600/12,06dfbb19faece3\", \t\t\t\t\t\"phoneNum\": \"11067854653\", \t\t\t\t\t\"tableId\": \"0cb7f275-9fb3-434e-9122-e59f551443ea\", \t\t\t\t\t\"tableName\": \"底库123412\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001100121231977\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"男\", \t\t\t\t\t\"likePer\": \"48\", \t\t\t\t\t\"monitorLevel\": \"2\", \t\t\t\t\t\"personId\": \"fed7b71c-d5eb-4feb-86d9-0522d7034412\", \t\t\t\t\t\"personName\": \"李逍遥\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/11,06dfb71c698169\", \t\t\t\t\t\"phoneNum\": \"11012344321\", \t\t\t\t\t\"tableId\": \"f008bf89-9406-490d-868b-6dd679cae954\", \t\t\t\t\t\"tableName\": \"同步库2\" \t\t\t\t}, \t\t\t\t{ \t\t\t\t\t\"IDCard\": \"54319001202319872643\", \t\t\t\t\t\"content\": \"\", \t\t\t\t\t\"gender\": \"女\", \t\t\t\t\t\"likePer\": \"97\", \t\t\t\t\t\"monitorLevel\": \"3\", \t\t\t\t\t\"personId\": \"f290bb54-4de8-496b-8612-a8c563ab45e1\", \t\t\t\t\t\"personName\": \"令狐冲\", \t\t\t\t\t\"personPicUrl\": \"http://192.168.1.203:9601/8,06dfb8facdaf8a\", \t\t\t\t\t\"phoneNum\": \"11039876431\", \t\t\t\t\t\"tableId\": \"ce228150-448b-4e70-9b08-374ed7c5bc3e\", \t\t\t\t\t\"tableName\": \"123\" \t\t\t\t} \t\t\t], \t\t\t\"content\": \"\", \t\t\t\"gender\": \"男\", \t\t\t\"id\": \"3bce3eef-2062-456e-b5cb-d1a4cc63c158\", \t\t\t\"indeviceName\": \"视频分析设备244\", \t\t\t\"personIsHub\": \"1\", \t\t\t\"picAddress\": \"测试地址\", \t\t\t\"picDate\": \"2019-05-17 12:19:16\", \t\t\t\"picMaxUrl\": \"http://58.118.225.79:44280/group4/M00/07/6A/rBEy8VzbhTaABvYpAAgn7hKYC2g311.jpg\", \t\t\t\"picSmUrl\": \"http://58.118.225.79:44280/group2/M00/00/B4/rBEy9Fx1Bn-AS7idAAAgkMt8drY443.jpg\", \t\t\t\"race\": \"黑人\", \t\t\t\"sdkType\": \"人脸\", \t\t\t\"taskName\": \"face\", \t\t\t\"videoIp\": \"172.17.50.244\", \t\t\t\"videoNum\": \"http://192.168.1.203:9600/12,017dae9d21ac08\", \t\t\t\"videoReqNum\": \"cid2\" \t\t} \t], \t\"total\": 5 }";
                            parseJson(msg);
                            SystemClock.sleep(2000);
                            continue;
                        }
                        if (System.currentTimeMillis() - lastUpdateTime < 30 * 1000) {
                            SystemClock.sleep(10 * 1000);
                            continue;
                        }
                        ip = SettingManager.getIpStr();
                        port = SettingManager.getPort();
                        try {
                            closeAllSockets();
                            System.out.println("断开原来所有连接");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        SystemClock.sleep(10 * 1000);
                        socket = new Socket();
                        socketAdd(socket);
                        socket.connect(new InetSocketAddress(ip, port), 3000);
                        System.out.println("连接成功");
//                    socket.connect(new InetSocketAddress(ip, 7000), 3000);
                        inputStream = new BufferedInputStream(socket.getInputStream());
                        outputStream = new BufferedOutputStream(socket.getOutputStream());
                        int len = 0;
                        lastUpdateTime = System.currentTimeMillis();
                        while ((len = inputStream.read(buff)) != -1) {
                            for (int i1 = 0; i1 < len; i1++) {
                                if (buff[i1] == '\0') {
                                    try {
                                        byte[] msgBuf = byteArrayOutputStream.toByteArray();
                                        byteArrayOutputStream.reset();
                                        msg = new String(msgBuf, 0, msgBuf.length);
                                        msg = msg.substring(0, msg.lastIndexOf("}") + 1);
                                        System.out.println("msg=" + msg);
                                        if (msg.length() > 3) {
                                            parseJson(msg);
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    lastUpdateTime = System.currentTimeMillis();
                                } else {
                                    byteArrayOutputStream.write(buff[i1]);
                                }
                            }
                            if (needRestart) {
                                needRestart = false;
                                break;
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("SocketClient:110, " + e.getMessage());
                        if (e instanceof InterruptedException) {
                            System.out.println("中断异常, 退出程序");
                            return;
                        }
                    } finally {
                        if (socket != null) {
                            try {
                                socket.close();
                                socket = null;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                        System.out.println("准备20秒后重连");
                        SystemClock.sleep(20 * 1000);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof InterruptedException) {
                System.out.println("中断异常, 退出程序");
                return;
            }
        } finally {
            try {
                if (outputStream != null) {
@@ -222,4 +307,13 @@
    }
    public void closeSocket() {
        try {
            if (socket != null) {
                socket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}