whyclj
2019-11-02 7b0d9dc2adc6da45cb5593456c58d83a21de0cfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.dev.fbs9009;
 
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
 
import com.base.Com;
import com.battdata_rt.BattData_RT_Array;
import com.config.AppConfig;
import com.sql.MysqlConnPool;
 
public class MyModBusServerSocketThread extends Thread{
    private MysqlConnPool m_ConnPool = null;
    private BattData_RT_Array m_Data;
    private AppConfig m_app_cfg;
    
    public MyModBusServerSocketThread(MysqlConnPool pool, BattData_RT_Array data, AppConfig cfg)
    {
        m_ConnPool = pool;
        m_Data = data;
        m_app_cfg = cfg;        
    }
    
    @Override
    public void run() {
        System.out.println(this.getName() + " - MyModBusServerSocketThread start at"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        
        //´´½¨LD9É豸µÄ״̬
        MyModBusSocketThread_SQL.createLD9_state(m_ConnPool);        
        
        //´´½¨LD9É豸µÄ²ÎÊý
        MyModBusSocketThread_SQL.createLD9_setparam(m_ConnPool);
        
        //´´½¨LD9É豸µÄ»ã¼¯Æ÷²ÎÊý±í
        MyModBusSocketThread_SQL.createConcentratParamTable(m_ConnPool);
        
        //´´½¨LD9É豸µÄ»ã¼¯Æ÷״̬±í
        MyModBusSocketThread_SQL.createConcentratStateTable(m_ConnPool);
        
        ServerSocket server = null;
        while(true) {
            try {
                System.out.println("MyModBusServerSocketThread Listen port at 9009");
                //¼àÌý9009¶Ë¿Ú
                server = new ServerSocket(9009);
                while(true) {
                    Socket tmp_socket = server.accept();
                    MyModBusSocketThread client 
                            = new MyModBusSocketThread(m_ConnPool, m_Data, tmp_socket);
                    client.start();
                }
            } catch (IOException e) {
                e.printStackTrace();
                try {
                    server.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    
    public static void main(String[] args) {
        MysqlConnPool pool = new MysqlConnPool("192.168.0.34",3360,10);
        BattData_RT_Array array = new BattData_RT_Array(null, null, pool);
        MyModBusServerSocketThread thread = new MyModBusServerSocketThread(pool,array,null);
        thread.start();
    }
}