Qt - Multiple Shared Memory spaces for multiple IPC apps?
I'm a bit new to Qt and I'm trying to understand Shared Memory applications and what happens when you have multiple pieces of software that use Shared Memory but are not supposed to interact.
I'm looking at this basic demo/example: http://doc.qt.io/qt-5/qtcore-ipc-sharedmemory-example.html
Lets say I develop software app A and software app B. Both of these apps use Qt's Shared Memory and are made to communicate to eachother using Shared Memory.
Then lets say the user also is running software app X that 开发者_运维知识库also happens to use Qt's Shared Memory for some other purpose. Software app X is completely UNRELATED to app A and app B.
Looking at the documentation for Qt's Shared Memory, I don't understand how your application use's Shared Memory in a way that differentiates itself from other applications attempting to use Shared Memory. What is keeping App X from sending garbage data to App A and App B via Shared Memory?
Also, one big question about the above example is that for Qt's Shared Memory demo, they use a single application that you run more than once and the Shared Memory stuff happens between them. Are you able to develop two completely different pieces of software that work together via Shared Memory or is it limited to a single application that is has multiple instances open?
Looking at the documentation for Qt's Shared Memory, I don't understand how your application use's Shared Memory in a way that differentiates itself from other applications attempting to use Shared Memory.
You make use of a key that your applications share. Thus can be set via the constructor:
QSharedMemory::QSharedMemory ( const QString & key, QObject * parent = 0 )
Or the function setKey():
void QSharedMemory::setKey ( const QString & key )
But, if another application used the same key, or guess your key you can have trouble. Thus, one way to protect against this is some form of obfuscation to generate your key.
Also, one big question about the above example is that for Qt's Shared Memory demo, they use a single application that you run more than once and the Shared Memory stuff happens between them. Are you able to develop two completely different pieces of software that work together via Shared Memory or is it limited to a single application that is has multiple instances open?
The use of shared memory is to share data between separate processes on the same host. Thus, it might be multiple instances of the same application or other applications that know or share the key.
精彩评论