Inter-process communication

前端 未结 9 1371
傲寒
傲寒 2020-12-01 08:42

I have two applications: X and Y.
X is the main application and it handles a lot of XML files. It has a history of more than 10 years and half a dozen techniques have

相关标签:
9条回答
  • 2020-12-01 08:53

    Named pipes are fast, because they are based on memory mapped files, for their implementation. What could be slow is the timeout in case of server failure...

    If you need to have fast response on the same computer, why don't you use good old GDI messages?

    You can use these messages, even with no User Interface or visual form, in plain console or background service applications (in case of a service application, the security settings must specify that this service must interact with the desktop, that is, must be able to receive and send messages).

    The trick is to handle WM_COPYDATA messages. See for example our TSQLRestClientURIMessage class, and the ExportServerMessage/AnswerToMessage methods of TSQLRestServer, as implemented in http://synopse.info/fossil/finfo?name=SQLite3/SQLite3Commons.pas

    In practice, I found out that GDI messages are much faster than named pipes for small amount of data (up to 64 KB or such per message).

    You have alternatives in Looking for an alternative to windows messages used in inter-process communication

    0 讨论(0)
  • 2020-12-01 08:59

    Have a look at my IPC at:

    http://www.cromis.net/blog/downloads/cromis-ipc/

    It is fast, free and has a setable timeout, so you can set it to a very small amount (50ms for example). Because it is very fast (typical message cycle request -> process -> response takes less than 1ms, around 0.1ms) you can have very small timeouts. It has client server build into it, so many clients are no problem. It runs threaded with task pool behind so it does not freeze your program and it has very flexible data packets to ease writing / reading the data.

    As already said you can even check with other means if the debugger is running.

    • Check for process
    • Check for main window of the process
    • Use a Mutex
    • ...
    0 讨论(0)
  • 2020-12-01 09:03

    If you are willing to use temporary file as transport, then it will be easy

    1. Both programs register a same custom message on start up MsgAppNotifyID := RegisterWindowMessage(......);

    2. Program Y must have codes to handle the custom message using SetWindowLong or anything equivalent

    3. Program X, using FindWindow to see if program Y is running or not

    4. Program X, If Y is running, Create a temp file on known location/directory of both end using consistent file name such as XXYY1234 (XXYYn) format where 1234=n

    5. Program X, use BroadcastSystemMessage to signal program Y NotifyRecipients := BSM_APPLICATIONS; BroadcastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE or BSF_FORCEIFHUNG, @NotifyRecipients, MsgAppNotifyID, any custom value, n);

    6. Program y, process above message using WParam as n and reconstruct the file for process

    Cheers Good luck

    0 讨论(0)
  • 2020-12-01 09:07

    running a TCP server which just on a connect (as a trigger) is really fast and should do what you want

    0 讨论(0)
  • 2020-12-01 09:09

    You could have X write its output to a memory-mapped file - Y can retrieve the data if it is running. This way X does not care whether or not Y is up.

    X could write some kind of control info at a known location (eg. store the offsets of last 1000 written XMLs starting at offset 0 in the mapped file) and use the rest of the file as a circular buffer for the raw data.

    If you need Y to be the determining factor for actions in X, have Y create the mapped file, and then use its presence/absence as a check on the data production on the X side of the 'channel'. There is example code for creator and second user here.

    0 讨论(0)
  • 2020-12-01 09:10

    Use memory-mapped files. They are great for your particular tasks. And our MsgConnect with it's MMF transport will come to rescue if you don't have time or intention to implement custom scheme.

    0 讨论(0)
提交回复
热议问题