2

I am trying to design a Client Server kind of application in which my Server is a daemon that accepts client requests, send client's data over a serial channel to the other side(which is an MCU and its firmware will reply to the Server request over the same serial channel). My client can be a CLI application or any other system program.

My idea of design is -

  1. Use message queues for communication between Client and Server since this is a local application and message queues are bidirectional and fast.
  2. Implement a LIBRARY that acts as an interface between multiple clients and the server. This basically does the stuff of packetizing client data into a message(own defined protocol), create message queues, connect to server, send/receive data and then pass it to the respective client(using call backs). This library also exposes API that can be used by clients. Thus this library gives me the flexibility to add support for any new clients keeping the server program unchanged.
  3. Server gets the data over serial from other side and passes it to the library over message queue. The library uses callbacks to send data to the client.

EDIT: I am thinking of creating Message queues on the fly when any client requests arrive. If I do this, how does the Server daemon(which has already started at linux boot up) gets information about this message queue? Does the message queue has a name that is persistent across and used by other programs? I want to implement clients that will be blocked until it gets response from the server.

Could you guys please review this design and tell me whether my approach is correct. Please reply if you have any other recommendations.

Thanks in advance.

Megatron
  • 101
  • 1
  • 1
  • 7
  • Message queues are indeed very fast. Be mindful of the maximum size of each message (and maximum number of messages in-flight) for your system. – Paul Dardeau Feb 10 '14 at 23:32
  • Thanks for your reply Paul. My messages are very small, not more than 255 bytes. And more over I am using a separate message queue for each client. do you think the design is OK? – Megatron Feb 11 '14 at 00:02
  • So length may not be an issue. Which msg queue type - sysV or POSIX? Are permissions going to be a stumbling block? How are the server and your lib going to negotiate new client queues - IOW, who creates them and by what mechanism does it inform the other? Just some things to think about. – Duck Feb 11 '14 at 00:10
  • Thanks for your reply Duck. I am going to use POSIX MQs. During startup, Server creates three message queues(right now I have three client apps). Whenever a client program wants to talk to server, it calls an init API of library that establishes connection with server using that particular MQ. Here the Library will act as interface between client and server. Library will receive data from Server and then sends data to the client through a call back. Does this sound ok? – Megatron Feb 11 '14 at 00:46
  • I guess that's fine if it really meets your needs but the library would be more useful if it requested the queues on demand. With your current direction you will need to change and recompile each time you want to add a client - or go thru some inifile rigmarole. Also posix queues are hard harder to use bi-directionally so commonly you have one for output & another for input. Also, are the calls to your lib going to block if you block on a queue or asynchronous? Lastly, cleanup. The queues are kernel persistent so you don't want them laying around after a failure. – Duck Feb 11 '14 at 01:45
  • I'm not trying to be a PITA, just giving you things to think about. – Duck Feb 11 '14 at 01:45
  • Thankyou Duck for your valuable suggestions. In fact, I was also not sure on how should I design this. I thought of creating Message queues on the fly when any client requests arrive. If I do like this, how does the Server daemon(which has already started at linux boot up) gets information about this message queue? About your question of blocking calls, yes, my client will be blocked until he gets response from the server. Could you please help? – Megatron Feb 11 '14 at 03:21

0 Answers0