예제 #1
0
        public NetworkMessage CreateNetworkMessage(BinaryReader reader)
        {
            uint         byteCount  = reader.NetworkReadUInt32();
            CmppCommands command    = (CmppCommands)reader.NetworkReadUInt32();
            uint         sequenceId = reader.NetworkReadUInt32();

            CmppMessage message = null;

            switch (command)
            {
            case CmppCommands.Connect:
                message = new CmppMessageConnect();
                break;

            case CmppCommands.ConnectResponse:
                message = new CmppMessageConnectResponse();
                break;

            case CmppCommands.Submit:
                message = new CmppMessageSubmit();
                break;

            case CmppCommands.SubmitResponse:
                message = new CmppMessageSubmitResponse();
                break;

            case CmppCommands.Deliver:
                message = new CmppMessageDeliver();
                break;

            case CmppCommands.DeliverResponse:
                message = new CmppMessageDeliverResponse();
                break;

            case CmppCommands.ActiveTest:
                message = new CmppMessageActiveTest();
                break;

            case CmppCommands.ActiveTestResponse:
                message = new CmppMessageActiveTestResponse();
                break;

            case CmppCommands.Terminate:
                message = new CmppMessageTerminate();
                break;

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

            if (message != null)
            {
                message.Command    = command;
                message.ByteCount  = byteCount;
                message.SequenceId = sequenceId;
                message.NetworkRead(reader);
            }
            return(message);
        }
예제 #2
0
        protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message)
        {
            if (this._isSimulated)
            {
                await base.DoNetworkMessageReceived(session, message);

                return;
            }
            if (message is CmppMessageConnect)
            {
                var m = message as CmppMessageConnect;

                var isAuthenticated = this.IsAuthenticated(m);

                if (isAuthenticated)
                {
                    var r = new CmppMessageConnectResponse();

                    r.SequenceId        = m.SequenceId;
                    r.Version           = 0x30;
                    r.AuthenticatorISMG = new byte[16];
                    r.Status            = 0;

                    session.UserId = m.SourceAddress;
                    await session.SendAsync(r);

                    this.OnSessionConnected(session);
                }
                else
                {
                    var tmp = session.StopAsync();
                }
            }
            else if (message is CmppMessageSubmit)
            {
                var m = message as CmppMessageSubmit;


                var r = new CmppMessageSubmitResponse();
                r.SequenceId = m.SequenceId;
                r.MessasgeId = this.GetMessageId();
                r.Result     = 0;

                this.SubmitQueue.Enqueue(new CmppSmsServerSubmitContext()
                {
                    Submit    = m,
                    MessageId = r.MessasgeId,
                    UserId    = session.UserId
                });
                await session.SendAsync(r);
            }
            else if (message is CmppMessageActiveTest)
            {
                var m = message as CmppMessageActiveTest;
                var r = new CmppMessageActiveTestResponse();
                r.SequenceId = m.SequenceId;
                await session.SendAsync(r);
            }
        }
예제 #3
0
 private async Task DoReceiveConnectResponseAsync(CmppMessageConnectResponse response)
 {
     await Task.Run(() =>
     {
         if (response.Status == CmppConstancts.ConnectResponseStatus.Success)
         {
             this.Status = SmsClientStatus.Connected;
             this.ConnectEvent.Set();
         }
     });
 }
예제 #4
0
        protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message)
        {
            if (message is CmppMessageConnect)
            {
                var m = message as CmppMessageConnect;
                var r = new CmppMessageConnectResponse();
                r.SequenceId        = m.SequenceId;
                r.Version           = 0x30;
                r.AuthenticatorISMG = new byte[16];
                r.Status            = 0;
                await session.SendAsync(r);
            }
            else if (message is CmppMessageSubmit)
            {
                var m = message as CmppMessageSubmit;

                var r = new CmppMessageSubmitResponse();
                r.SequenceId = m.SequenceId;
                r.MessasgeId = this.GetMessageId();
                r.Result     = 0;

                await session.SendAsync(r);

                var time   = DateTime.Now;
                var report = new CmppMessageReport()
                {
                    Id   = r.MessasgeId,
                    Stat = "DELIVRD",
                    ReceiverTerminalId = m.ReceiverTerminalIds[0],
                    CompleteTime       = time.AddMinutes(20).ToString("yyMMddHHmm"),
                    SubmitTime         = time.ToString("yyMMddHHmm"),
                    SmscSequence       = 0,
                };
                var d = new CmppMessageDeliver()
                {
                    SequenceId             = this.SequenceId,
                    Id                     = r.MessasgeId,
                    Format                 = (byte)CmppEncodings.ASCII,
                    ReceiverId             = m.ReceiverTerminalIds[0],
                    ServiceId              = _serviceId,
                    DeliveryReportRequired = 1,//状态报告
                    ServiceTerminalId      = _serviceId,
                    LinkId                 = string.Empty
                };
                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 CmppMessageActiveTest)
            {
                var m = message as CmppMessageActiveTest;
                var r = new CmppMessageActiveTestResponse();
                r.SequenceId = m.SequenceId;
                await session.SendAsync(r);
            }
        }