private void _ConnectInternal() { if (Status != Cmpp30ClientStatus.Disconnected) { return; } if (_transport.Connected) { _transport.Disconnect(); } Status = Cmpp30ClientStatus.Connecting; StatusText = ""; _transport.Connect(); if (!_transport.Connected) { Status = Cmpp30ClientStatus.Disconnected; StatusText = "Fail to connect"; } Status = Cmpp30ClientStatus.Authenticating; try { var timestamp = DateTime.Now; var connect = new CmppConnect { TimeStamp = uint.Parse(string.Format("{0:MMddhhmmss}", timestamp)), AuthenticatorSource = CreateAuthenticatorSource(timestamp), Version = CmppConstants.Version, SourceAddress = _config.GatewayUsername, }; _lastTransferTime = DateTime.Now; if (_transport.Send(NextSequenceId, connect)) { return; } _Disconnect(); StatusText = "Fail to send"; } catch (Exception ex) { log.Error("Error sending authenticating. error: ", ex); _Disconnect(); StatusText = ex.Message; } }
private SmsPacket GetConnectRequestPacket(string userName, string password) { var date = DateTime.Now; authenticatorSource = CmppTools.CreateAuthenticatorSource(date, userName, password); IMessage message = new CmppConnect() { TimeStamp = uint.Parse(string.Format("{0:MMddHHmmss}", date)), AuthenticatorSource = authenticatorSource, Version = CmppConstants.Version, SourceAddress = userName, }; return(CmppTools.GroupPacket(message)); }