Exemple #1
0
 /// <summary>
 /// Callback method to handle socket closing.
 /// </summary>
 /// <param name="client">The client to receive messages from.</param>
 internal void ClientCloseHandler(AsyncSocketClient client)
 {
     //fire off a closing event
     if (OnClose != null)
     {
         System.EventArgs e = new System.EventArgs();
         OnClose(this, e);
     }
 }
Exemple #2
0
 /// <summary>
 /// Callback method to handle errors.
 /// </summary>
 /// <param name="client">The client to receive messages from.</param>
 /// <param name="exception">The generated exception.</param>
 internal void ClientErrorHandler(AsyncSocketClient client,
                                  Exception exception)
 {
     //fire off an error handler
     if (OnError != null)
     {
         CommonErrorEventArgs e = new CommonErrorEventArgs(exception);
         OnError(this, e);
     }
 }
Exemple #3
0
 /// <summary>
 /// Start processing server connected client
 /// </summary>
 /// <param name="client"></param>
 public void ProcessServerClient(AsyncSocketClient client)
 {
     _serverMode               = true;
     asClient                  = client;
     _Host                     = asClient.ServerIPAddress;
     _Port                     = asClient.ServerPort;
     _SentUnbindPacket         = false;
     asClient.MessageRecieved += ClientMessageHandler;
     asClient.TranciverFailed += ClientErrorHandler;
     asClient.SocketClosed    += ClientCloseHandler;
 }
 /// <summary>
 /// Callback method to handle received messages.  The AsyncSocketClient
 /// library calls this; don't call it yourself.
 /// </summary>
 /// <param name="client">The client to receive messages from.</param>
 internal void ClientMessageHandler(AsyncSocketClient client)
 {
     try
     {
         Queue responseQueue = new PduFactory().GetPduQueue(client.Buffer);
         ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPduQueue), responseQueue);
     }
     catch (Exception exception)
     {
         if (OnError != null)
         {
             CommonErrorEventArgs e = new CommonErrorEventArgs(exception);
             OnError(this, e);
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Unbinds the SMPPCommunicator from the SMSC then disconnects the socket
        /// when it receives the unbind response from the SMSC.  This will also stop the
        /// timer that sends out the enquire_link packets if it has been enabled.  You need to
        /// explicitly call this to unbind.; it will not be done for you.
        /// </summary>
        public void Unbind()
        {
            if (timer != null)
            {
                timer.Stop();
            }

            if (!_SentUnbindPacket && IsBinded)
            {
                SmppUnbind request = new SmppUnbind();
                SendPdu(request);
                _SentUnbindPacket = true;
            }
            asClient.Dispose();
            asClient  = null;
            _isBinded = false;
        }
Exemple #6
0
        /// <summary>
        /// Connects and binds the SMPPCommunicator to the SMSC, using the
        /// values that have been set in the constructor and through the
        /// properties.  This will also start the timer that sends enquire_link packets
        /// at regular intervals, if it has been enabled.
        /// </summary>
        /// <remarks>
        /// Can be used only in client mode
        /// </remarks>
        public void Bind()
        {
            if (!_serverMode)
            {
                try
                {
                    if (asClient != null)
                    {
                        asClient.Disconnect();
                    }
                }
                catch
                {
                    //drop it on the floor
                }

                //connect
                try
                {
                    asClient = new AsyncSocketClient(10240, null,
                                                     new AsyncSocketClient.MessageHandler(ClientMessageHandler),
                                                     new AsyncSocketClient.SocketClosingHandler(ClientCloseHandler),
                                                     new AsyncSocketClient.ErrorHandler(ClientErrorHandler));

                    asClient.Connect(Host, Port);

                    SmppBind request = new SmppBind();
                    request.SystemId         = SystemId;
                    request.Password         = Password;
                    request.SystemType       = SystemType;
                    request.InterfaceVersion = Version;
                    request.AddressTon       = TonType;
                    request.AddressNpi       = NpiType;
                    request.AddressRange     = AddressRange;
                    request.BindType         = BindType;

                    SendPdu(request);
                    _SentUnbindPacket = false;
                    _isBinded         = true;

                    if (_EnquireLinkInterval > 0)
                    {
                        if (timer == null)
                        {
                            timer          = new System.Timers.Timer();
                            timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
                        }

                        if (timer != null)              //reset the old timer
                        {
                            timer.Stop();

                            timer.Interval = EnquireLinkInterval * 1000;
                            timer.Start();
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (OnError != null)
                    {
                        OnError(this, new CommonErrorEventArgs(exc));
                    }
                }
            }
        }