Example #1
0
 private async Task DoReceiveLoginResponseAsync(SmgpMessageLoginResponse response)
 {
     await Task.Run(() =>
     {
         if (response.Status == 0)
         {
             this.Status = SmsClientStatus.Connected;
             this.ConnectEvent.Set();
         }
     });
 }
Example #2
0
        protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message)
        {
            if (message is SmgpMessageLogin)
            {
                var m = message as SmgpMessageLogin;
                var r = new SmgpMessageLoginResponse();
                r.SequenceId = m.SequenceId;
                r.Version    = m.Version;
                r.Signature  = new byte[16];
                r.Status     = 0;
                await session.SendAsync(r);
            }
            else if (message is SmgpMessageSubmit)
            {
                var m = message as SmgpMessageSubmit;
                var r = new SmgpMessageSubmitResponse();
                r.SequenceId = m.SequenceId;
                r.Status     = 0;
                r.Id         = Guid.NewGuid().ToByteArray().Take(10).ToArray();

                await session.SendAsync(r);

                var time   = DateTime.UtcNow;
                var report = new SmgpMessageReport();
                report.Id           = r.Id;
                report.Status       = "DELIVRD";
                report.SubmitTime   = time.ToString("yyMMddHHmm");
                report.CompleteTime = time.ToString("yyMMddHHmm");
                report.Text         = Encoding.GetEncoding("gb2312").GetBytes(m.Content);
                report.Error        = "001"; //err
                report.Submited     = "001"; //sub
                report.Delivered    = "001"; //dkvrd;

                var d = new SmgpMessageDeliver()
                {
                    SequenceId     = this.SequenceId,
                    Id             = r.Id,
                    Format         = (byte)SmgpEncodings.GBK,
                    ReceiverId     = m.ReceiverIds[0],
                    ReportRequired = 1,//IsReport
                    SenderId       = m.SenderId,
                    ReceiveTime    = time.ToString("yyyyMMddHHmmss")
                };

                d.SetReport(report);

                await session.SendAsync(d);

                lock (this)
                {
                    _submitCount++;
                    var stamp = DateTime.Now;

                    if (_startStamp == DateTime.MinValue)
                    {
                        _startStamp = stamp;
                    }
                    _endStamp = stamp;

                    var tick = (long)(_endStamp - _startStamp).TotalSeconds;
                    if (tick != _reportTick)
                    {
                        _reportTick = tick;
                        Console.WriteLine("{0}: {1}...", _submitCount, stamp.ToLongTimeString());
                    }
                }
            }
            else if (message is SmgpMessageActiveTest)
            {
                var m = message as SmgpMessageActiveTest;
                var r = new SmgpMessageActiveTestResponse();
                r.SequenceId = m.SequenceId;
                await session.SendAsync(r);
            }
        }
Example #3
0
        public NetworkMessage CreateNetworkMessage(BinaryReader reader)
        {
            uint         byteCount  = reader.NetworkReadUInt32();
            SmgpCommands command    = (SmgpCommands)reader.NetworkReadUInt32();
            uint         sequenceId = reader.NetworkReadUInt32();

            SmgpMessage message = null;

            switch (command)
            {
            case SmgpCommands.Login:
                message = new SmgpMessageLogin();
                break;

            case SmgpCommands.LoginResponse:
                message = new SmgpMessageLoginResponse();
                break;

            case SmgpCommands.Submit:
                message = new SmgpMessageSubmit();
                break;

            case SmgpCommands.SubmitResponse:
                message = new SmgpMessageSubmitResponse();
                break;

            case SmgpCommands.Deliver:
                message = new SmgpMessageDeliver();
                break;

            case SmgpCommands.DeliverResponse:
                message = new SmgpMessageDeliverResponse();
                break;

            case SmgpCommands.ActiveTest:
                message = new SmgpMessageActiveTest();
                break;

            case SmgpCommands.ActiveTestResponse:
                message = new SmgpMessageActiveTestResponse();
                break;

            case SmgpCommands.Exit:
                message = new SmgpMessageExit();
                break;

            case SmgpCommands.ExitResponse:
                message = new SmgpMessageExitResponse();
                break;

            default:
                message = new SmgpMessage();
                break;
            } //end switch

            if (message != null)
            {
                message.Command    = command;
                message.ByteCount  = byteCount;
                message.SequenceId = sequenceId;
                message.NetworkRead(reader);
            }
            return(message);
        }