1

I am making a (very basic) distributed application that has a Python server and a C# client talking to each other via json over ZeroMQ. When a method is invoked in client, it composes a message and sends it to the server where a corresponding function is executed, so it's basically a sort of an RPC.

To understand what to do with the messages, the app relies on a 'protocol' (in fact a set of keywords) which is duplicated on client and server side, something like this:

namespace Draftsocket
{
    public static class Protocol
    {
        public struct ClientAction
        {
            //client-issued action lines
            public const string CMD = "COMMAND";
            public const string ERROR = "CLIENT_ERROR";
            public const string EVENT = "EVENT";
            public const string CONTINUE = "CONTINUE";
            public const string CONSOLE = "CONSOLE";
        }
    ...etc...

(link to complete file in C#)

class Protocol(object):

    class ClientAction:
        CMD = "COMMAND"
        ERROR = "CLIENT_ERROR"
        EVENT = "EVENT"
        CONTINUE = "CONTINUE"
        CONSOLE = "CONSOLE"
...etc...

(link to complete file in Python)

This is then used to compose and read messages, like this:

public static ClientMessage NewCommand(string Name)
{
    return new ClientMessage(Protocol.ClientAction.CMD, Protocol.Status.OK, Name);
}

This works for the time being but is generally awful: stringly-typed and inconvenient for anyone who will want to use the application as a framework to build on.

I can't decide on how to refactor this protocol in a way that would either automate/sync to each other the language-specific implementations or, for example, fire up a warning if the protocol are out of sync/outdated?

Guess that I should look into Enums and/or something of the sort MessagePack implements, but I don't feel qualified enough to proceed on my own with this.

TIA.

Alex Bausk
  • 625
  • 5
  • 26

1 Answers1

2

I would use protobuf or thrift. They are meant to solve the problem of data exchange between different platforms. See this for example: Biggest differences of Thrift vs Protocol Buffers?

Community
  • 1
  • 1
fejesjoco
  • 11,307
  • 3
  • 31
  • 63
  • Protobuf then?.. I've been directed to use them before so I'll look into that. Were protocol buffers designed to solve exactly this kind of problems or do they just happen to have this secondary use? – Alex Bausk Dec 02 '13 at 17:05