Ejemplo n.º 1
0
        public void TestMethod_PAM()
        {
            //測試取PAM水位加值的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server4.Start();
            //send data(ComType:0631)
            string sendPRhexData = "010101032200000002000001000386043131328D3780    KRT00100000001100110000001920000019200000000000001KRT0000000600000000001000086043131328D3780600000201603040000001520160308105037FCBB8B08        ";

            byte[]     sendPRData = StringToByteArray(sendPRhexData);//轉一下
            string     url        = "127.0.0.1";
            int        port       = 8116;
            int        testCount  = 2;//20;//非同步連線總次數,太高就爆了
            IPEndPoint ep         = new IPEndPoint(IPAddress.Parse(url), port);

            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket   client  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj()
                {
                    clientNo = i, mainSocket = client, sendData = sendPRData, receiveSignList = taskCount, receiveDataList = receiveList
                };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(18000);//等所有任務完成:最多等18秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }
Ejemplo n.º 2
0
        public void TestMethod_AutoLoad()
        {
            //測試自動加值的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server2.Start();
            //send data(ComType:0332)
            string sendAutoLoadhexData = "3031303130313033333230303030303030313836303030303030303138363034303432423641394632393830202020205345543030313030313434343633313030313130303030303031343730303030303134372020202020202020202020203033202020202020202020202020202020205656565656565656565656565656565632303136303131333135353435393030303030313030303030303030303030303530303030303030303030303030303030303030303030681715998900002836383137313539393839303030303238323031363031303132303230303130313939393939393939414E4643314542353733";

            byte[]     sendAutoLoadData = StringToByteArray(sendAutoLoadhexData);//轉一下
            string     url       = "127.0.0.1";
            int        port      = 8114;
            int        testCount = 20;//非同步連線總次數,太高就爆了
            IPEndPoint ep        = new IPEndPoint(IPAddress.Parse(url), port);

            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket   client  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj()
                {
                    clientNo = i, mainSocket = client, sendData = sendAutoLoadData, receiveSignList = taskCount, receiveDataList = receiveList
                };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(13000);//等所有任務完成:最多等13秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }
Ejemplo n.º 3
0
        public void TestMethod_PurchaseReturn()
        {
            //測試一般加值TxLog的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server1.Start();
            //send data(ComType:0631)
            string sendPRhexData = "30313031303130363331303030303030303138363030303030303031383630343430323736413946323938302020202053455430303130303935393132323130303131303030303030313435303030303031343520202020202020202020202030322020202020202020202020202020202031352E37322E30312020202020202020323031353038313130303033333630353534393330303030303030303030303030343030303030000000000000000000000000000000007311140148024009373331313134303134383032343030393030303030303030323031373038313130303030303034393641383031393544";

            byte[]     sendPRData = StringToByteArray(sendPRhexData);//轉一下
            string     url        = "127.0.0.1";
            int        port       = 8113;
            int        testCount  = 20;//非同步連線總次數,太高就爆了
            IPEndPoint ep         = new IPEndPoint(IPAddress.Parse(url), port);

            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket   client  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj()
                {
                    clientNo = i, mainSocket = client, sendData = sendPRData, receiveSignList = taskCount, receiveDataList = receiveList
                };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(18000);//等所有任務完成:最多等18秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }
        public void TestMethod_AutoLoad()
        {
            //測試自動加值的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server2.Start();
            //send data(ComType:0332)
            string sendAutoLoadhexData = "3031303130313033333230303030303030313836303030303030303138363034303432423641394632393830202020205345543030313030313434343633313030313130303030303031343730303030303134372020202020202020202020203033202020202020202020202020202020205656565656565656565656565656565632303136303131333135353435393030303030313030303030303030303030303530303030303030303030303030303030303030303030681715998900002836383137313539393839303030303238323031363031303132303230303130313939393939393939414E4643314542353733";
            byte[] sendAutoLoadData = StringToByteArray(sendAutoLoadhexData);//轉一下
            string url = "127.0.0.1";
            int port = 8114;
            int testCount = 20;//非同步連線總次數,太高就爆了
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(url), port);
            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj() { clientNo = i, mainSocket = client, sendData = sendAutoLoadData, receiveSignList = taskCount, receiveDataList = receiveList };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(13000);//等所有任務完成:最多等13秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }
Ejemplo n.º 5
0
 //end Connect用的callabck方法
 private void ConnectCallback(IAsyncResult ar)
 {
     if (ar.IsCompleted)
     {
         stateObj obj = null;
         try
         {
             obj = (stateObj)ar.AsyncState;
             obj.mainSocket.EndConnect(ar);
             //Thread.Sleep(obj.clientNo * 10);//加入延遲,結果一樣後端延遲
             int    sendLength    = obj.mainSocket.Send(obj.sendData);
             byte[] buffer        = new byte[0x1000];
             int    receivelength = obj.mainSocket.Receive(buffer);
             Array.Resize(ref buffer, receivelength);
             obj.receiveDataList[obj.clientNo] = BitConverter.ToString(buffer).Replace("-", "");
         }
         catch (Exception ex)
         {
             if (obj != null)
             {
                 log.Error("Client[" + obj.clientNo + "]連線異常:" + ex.Message);
             }
         }
         finally
         {
             if (obj != null)
             {
                 if (obj.mainSocket != null)
                 {
                     try
                     {
                         obj.mainSocket.Shutdown(SocketShutdown.Both);
                     }
                     catch (Exception ex)
                     {
                         log.Error("client[" + obj.clientNo + "]關閉時爆了" + ex.Message);
                     }
                     obj.mainSocket.Close(1000);
                     obj.mainSocket.Dispose();
                     obj.mainSocket = null;
                 }
                 //mission complete
                 obj.receiveSignList.Signal();
                 //remove point
                 obj.receiveSignList = null;
                 obj.receiveDataList = null;
             }
         }
     }
 }
        public void TestMethod_PurchaseReturn()
        {
            //測試一般加值TxLog的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server1.Start();
            //send data(ComType:0631)
            string sendPRhexData = "30313031303130363331303030303030303138363030303030303031383630343430323736413946323938302020202053455430303130303935393132323130303131303030303030313435303030303031343520202020202020202020202030322020202020202020202020202020202031352E37322E30312020202020202020323031353038313130303033333630353534393330303030303030303030303030343030303030000000000000000000000000000000007311140148024009373331313134303134383032343030393030303030303030323031373038313130303030303034393641383031393544";
            byte[] sendPRData = StringToByteArray(sendPRhexData);//轉一下
            string url = "127.0.0.1";
            int port = 8113;
            int testCount = 20;//非同步連線總次數,太高就爆了
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(url), port);
            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj() { clientNo = i, mainSocket = client, sendData = sendPRData, receiveSignList = taskCount, receiveDataList = receiveList };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(18000);//等所有任務完成:最多等18秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }
        public void TestMethod_PAM()
        {
            //測試取PAM水位加值的功能(多開)
            //start service //要確定Back-End Service和KMS 2.0服務可用
            this.server4.Start();
            //send data(ComType:0631)
            string sendPRhexData = "010101032200000002000001000386043131328D3780    KRT00100000001100110000001920000019200000000000001KRT0000000600000000001000086043131328D3780600000201603040000001520160308105037FCBB8B08        ";
            byte[] sendPRData = StringToByteArray(sendPRhexData);//轉一下
            string url = "127.0.0.1";
            int port = 8116;
            int testCount = 2;//20;//非同步連線總次數,太高就爆了
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(url), port);
            taskCount = new CountdownEvent(testCount);//callback sign告訴主程式完成任務用的
            string[] receiveList = new string[testCount];
            log.Debug("Client開始連線");
            for (int i = 0; i < testCount; i++)
            {
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                stateObj sendObj = new stateObj() { clientNo = i, mainSocket = client, sendData = sendPRData, receiveSignList = taskCount, receiveDataList = receiveList };
                client.BeginConnect(ep, ConnectCallback, sendObj);
            }

            taskCount.Wait(18000);//等所有任務完成:最多等18秒
            //列出所有接收到的訊息
            for (int j = 0; j < receiveList.Length; j++)
            {
                log.Info("Client[" + j + "] data:" + receiveList[j]);
                Assert.IsNotNull(receiveList[j]);
            }
        }