Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if the Observer (publisher) and Subject (subscriber) are on different process
ex. publisher application is running on one pc and the subscriber process in another pc how can i implement both observer and subscriber so that the subscriber can subscribe and the observer can notify ?

the concept which described here is for local application (where both applications are on same process )

thanks!
Posted

1 solution

The usual way to do this is via network sockets. The observers would connect to a network port on the subject PC, and the subject would pass notifications to all observers.

Since there's no standard C++ socket API, so how to code it exactly depends on your platform, but pretty much every OS has a variant of the Berkerley socket. There's a good introduction to it here: http://www.troubleshooters.com/codecorn/sockets/[^]

The next problem is how to transfer data from subject to observers, since you can't send pointers to areas of shared memory over the network. For this, you'll have to come up with a suitable protocol, which would normally be text-based.
 
Share this answer
 
Comments
Paul Heil 10-Nov-11 16:22pm    
If you're using Windows, MSDN has an article on the various methods of interprocess communications available: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx
ephrem33 14-Nov-11 4:02am    
ya i have to use Windows Sockets and the communication should be text based but i cant figure out how to develop my own protocol. i read the articles and are nice! thank you for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900