Example #1
0
 public void Init(Int32 index, Int32 number)
 {
     Index        = index;
     Number       = number;
     ClientSocket = new AsyncSocket();
     RecvPacketInfo.Init(DummyManager.Config.PacketSizeMax);
 }
Example #2
0
 public void Init(Int32 index, TestConfig config)
 {
     Index = index;
     SendPacket.Init(DummyManager.GetDummyInfo.PacketSizeMax);
     RecvPacket.Init(DummyManager.GetDummyInfo.PacketSizeMax);
 }
        //public Action<string> MsgFunc; //[진행중] [완료] [실패]

        public async Task <(bool, string)> EchoAsync(Dummy dummy, EchoCondition cond)
        {
            var clientSocket = dummy.ClientSocket;

            SendPacket.Init(cond.PacketSizeMax);
            RecvPacket.Init(cond.PacketSizeMax);

            int curEchoCount = 0;

            try
            {
                var(result, error) = await clientSocket.ConnectAsync(cond.IP, cond.Port);

                if (result == false)
                {
                    return(false, error);
                }

                while (true)
                {
                    // 스레드 잘 사용하는지 알기 위해 스레드 번호찍기
                    //Utils.Logger.Debug($"Echo-Send. ClientIndex: {dummy.Index}");

                    SendPacket.SetData(cond.PacketSizeMin, cond.PacketSizeMax);
                    var sendError = await clientSocket.SendAsync(SendPacket.BufferSize, SendPacket.BufferData);

                    if (sendError != "")
                    {
                        return(End(dummy, curEchoCount, false, sendError));
                    }


                    // 스레드 잘 사용하는지 알기 위해 스레드 번호찍기
                    //Utils.Logger.Debug($"Echo-Recv. ClientIndex: {dummy.Index}");

                    var(recvCount, recvError) = await clientSocket.ReceiveAsync(RecvPacket.BufferSize, RecvPacket.RecvBuffer);

                    if (recvError != "")
                    {
                        return(End(dummy, curEchoCount, false, recvError));
                    }

                    if (recvCount > 0)
                    {
                        RecvPacket.Received(recvCount);
                    }
                    else if (recvCount == 0)
                    {
                        return(End(dummy, curEchoCount, false, "연결 종료"));
                    }


                    if (SendPacket.BodyData() != RecvPacket.BodyData())
                    {
                        return(End(dummy, curEchoCount, false, "데이터 틀림"));
                    }


                    ++curEchoCount;

                    if (cond.IsEnd(curEchoCount))
                    {
                        break;
                    }
                }

                return(End(dummy, curEchoCount, true, ""));
            }
            catch (Exception ex)
            {
                return(false, ex.ToString());
            }
        }