Giter Club home page Giter Club logo

Comments (5)

drewnoakes avatar drewnoakes commented on July 27, 2024

Well spotted. Fancy making a pull request?

from samples.

Camuvingian avatar Camuvingian commented on July 27, 2024

Okay, I will do this tonight.

from samples.

Camuvingian avatar Camuvingian commented on July 27, 2024

There is also a miss-match in the way replies are handled for MDPClient vs MDPClientAsync. In the ProcessReceiveReady method we have in MDPClientAsync

private void OnProcessReceiveReady(object sender, NetMQSocketEventArgs e)
{
    Exception exception = null;
    NetMQMessage reply = null;
    try
    {
        reply = m_client.ReceiveMultipartMessage();
        if (ReferenceEquals(reply, null))
            throw new ApplicationException("Unexpected behavior");

        m_timer.EnableAndReset(); // reset timeout timer because a message was received

        Log($"[CLIENT INFO] received the reply {reply}");

        ExtractFrames(reply);
    }
    catch (Exception ex)
    {
        exception = ex;
    }
    finally
    {
        ReturnReply(reply, exception);
    }
}

private void ExtractFrames(NetMQMessage reply)
{
    if (reply.FrameCount < 4)
        throw new ApplicationException("[CLIENT ERROR] received a malformed reply");

    var emptyFrame = reply.Pop();
    if (emptyFrame != NetMQFrame.Empty)
    {
        throw new ApplicationException($"[CLIENT ERROR] received a malformed reply expected empty frame instead of: { emptyFrame } ");
    }
    var header = reply.Pop(); // [MDPHeader] <- [service name][reply] OR ['mmi.service'][return code]

    if (header.ConvertToString() != m_mdpClient)
        throw new ApplicationException($"[CLIENT INFO] MDP Version mismatch: {header}");

    var service = reply.Pop(); // [service name or 'mmi.service'] <- [reply] OR [return code]

    if (service.ConvertToString() != m_serviceName)
        throw new ApplicationException($"[CLIENT INFO] answered by wrong service: {service.ConvertToString()}");
}

Then in MDPClient

private void ProcessReceiveReady (object sender, NetMQSocketEventArgs e)
{
    // a message is available within the timeout period
    var reply = m_client.ReceiveMultipartMessage ();

    Log ($"\n[CLIENT INFO] received the reply {reply}\n");

    // in production code malformed messages should be handled smarter
    if (reply.FrameCount < 3)
        throw new ApplicationException ("[CLIENT ERROR] received a malformed reply");

    var header = reply.Pop (); // [MDPHeader] <- [service name][reply] OR ['mmi.service'][return code]

    if (header.ConvertToString () != m_mdpClient)
        throw new ApplicationException ($"[CLIENT INFO] MDP Version mismatch: {header}");

    var service = reply.Pop (); // [service name or 'mmi.service'] <- [reply] OR [return code]

    if (service.ConvertToString () != m_serviceName)
        throw new ApplicationException ($"[CLIENT INFO] answered by wrong service: {service.ConvertToString()}");
    // now set the value for the reply of the send method!
    m_reply = reply;        // [reply] OR [return code]
}

These should be the same, or have I missed something?

from samples.

somdoron avatar somdoron commented on July 27, 2024

I'm not sure, less familiar with this code sample. Anyway, if you think something is wrong, fix it and send a PR. If you are wrong, someday someone else will send a PR to fix that.

from samples.

Camuvingian avatar Camuvingian commented on July 27, 2024

Okay, fair enough. I am undergoing a process of creating a new type of transport mechanism based on Majordomo, if I find any further anomalies I will send a PR.

from samples.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.