Menu

Manager is disconnecting randomly

Anonymous
2012-11-13
2013-02-03
  • Anonymous

    Anonymous - 2012-11-13

    Hello,

    I'm developing application listening on incomig calls, but after login sometimes manager disconnnects and connect again after some time, I tried using SendAction(new PingAction()) but I get error after runing this command, any ideas what might be wrong?

    Regards,
    Konrad

     
  • Augustine

    Augustine - 2012-11-15

    Hi ,

    which language are you using to develope the Apps ?.

    Thank you

     
  • Augustine

    Augustine - 2012-11-15

    Hi ,

    I have used C# to develope this kind of Apps and it works quite well .

    let me know if you have any further issues.

    Thank you

     
  • Anonymous

    Anonymous - 2012-11-19

    I'm sorry for not replying to you I was on vacations few days.
    I'm using C# to but maybe my problems occurs because my asterisk server is 1.8 while library supports only 1.6 I made some changes in code to make it work with 1.8 but it was only one line accepting 1.8 vesion string

    Do you think incompatible version might be the problem?
    Regards,
    Konrad

     
  • Animha

    Animha - 2013-01-18

    I experienced the same disconnection problem on a Asterisk 1.8.
    I managed to find a bug in the library which was causing continuous disconnections instead of the correct Ping/Pong operation for keeping the connection alive.

    To fix this problem you can just edit the file ManagerConnection.cs to have it like this (modified parts are in BOLD):

    Note: the original code is from library sources version 1.6.3.1.

    internal void DispatchResponse(Dictionary<string, string> buffer, ManagerResponse response)
            {
                string responseActionId = string.Empty;
                string actionId = string.Empty;
                IResponseHandler responseHandler = null;
                [b]bool isPingResponse = false;[/b]
                if (buffer != null)
                {
                  [b]  if (buffer.ContainsKey("ping") && buffer["ping"] == "Pong")
                        isPingResponse = true;[/b]
                    if (buffer["response"].ToLower(Helper.CultureInfo) == "error")
                        response = new ManagerError(buffer);
                    else if (buffer.ContainsKey("actionid"))
                        actionId = buffer["actionid"];
                }
                if (response != null)
                    actionId = response.ActionId;
                [b]if (!string.IsNullOrEmpty(actionId) && !isPingResponse)[/b]
                {
                    int hash = Helper.GetInternalActionId(actionId).GetHashCode();
                    responseActionId = Helper.StripInternalActionId(actionId);
                    responseHandler = GetRemoveResponseHandler(hash);
                    if (response != null)
                        response.ActionId = responseActionId;
                    if (responseHandler != null)
                    {
                        if (response == null)
                        {
                            ManagerActionResponse action = responseHandler.Action as ManagerActionResponse;
                            if (action == null || (response = action.ActionCompleteResponseClass() as ManagerResponse) == null)
                                response = Helper.BuildResponse(buffer);
                            else
                                Helper.SetAttributes(response, buffer);
                            response.ActionId = responseActionId;
                        }
                        try
                        {
                            responseHandler.HandleResponse(response);
                        }
                        catch (Exception ex)
                        {
    #if LOGGER
                            logger.Error("Unexpected exception in responseHandler {0}\n{1}", response, ex);
    #else
                            throw new ManagerException("Unexpected exception in responseHandler " + responseHandler.GetType().FullName, ex);
    #endif
                        }
                    }
                }
    [b]         else if (response == null && isPingResponse) [/b]
                {
                    response = Helper.BuildResponse(buffer);
                    foreach (ResponseHandler pingHandler in pingHandlers.Values)
                        pingHandler.HandleResponse(response);
                    pingHandlers.Clear();
                }
                if (!reconnected)
                    return;
                if (response == null)
                {
                    response = Helper.BuildResponse(buffer);
                    response.ActionId = responseActionId;
                }
    #if LOGGER
                logger.Info("Reconnected - DispatchEvent : " + response);
    #endif
                #region Support background reconnect
                if (response is ChallengeResponse)
                {
                    string key = null;
                    if (response.IsSuccess())
                    {
                        ChallengeResponse challengeResponse = (ChallengeResponse)response;
                        string challenge = challengeResponse.Challenge;
                        try
                        {
                            Util.MD5Support md = Util.MD5Support.GetInstance();
                            if (challenge != null)
                                md.Update(UTF8Encoding.UTF8.GetBytes(challenge));
                            if (password != null)
                                md.Update(UTF8Encoding.UTF8.GetBytes(password));
                            key = Helper.ToHexString(md.DigestData);
                        }
    #if LOGGER
                        catch (Exception ex)
                        {
                            logger.Error("Unable to create login key using MD5 Message Digest", ex);
    #else
                        catch
                        {
    #endif
                            key = null;
                        }
                    }
                    bool fail = true;
                    if (!string.IsNullOrEmpty(key))
                        try
                        {
                            Action.LoginAction loginAction = new Action.LoginAction(username, "MD5", key);
                            SendAction(loginAction, null);
                            fail = false;
                        }
                        catch { }
                    if (fail)
                        if (keepAliveAfterAuthenticationFailure)
                            reconnect(true);
                        else
                            disconnect(true);
                }
                else if (response is ManagerError)
                {
                    if (keepAliveAfterAuthenticationFailure)
                        reconnect(true);
                    else
                        disconnect(true);
                }
                else if (response is ManagerResponse)
                {
                    if (response.IsSuccess())
                    {
                        reconnected = false;
                        enableEvents = true;
                        reconnectEnable = keepAlive;
                        ConnectEvent ce = new ConnectEvent(this);
                        ce.Reconnect = true;
                        ce.ProtocolIdentifier = protocolIdentifier;
                        fireEvent(ce);
                    }
                    else if (keepAliveAfterAuthenticationFailure)
                        reconnect(true);
                    else
                        disconnect(true);
                }
                #endregion
            }
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.