Click here to Skip to main content
15,920,836 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi, I'm a beginner in programming and have been learning for some time now. I'm trying to make an application that handles data particularly data for a hotel, like guest name, arrival date, etc... This application will be used for hotel receptionists so they would know which room is vacant or occupied, with views of guest lists, etc...

So my question is, If I put the application in a network drive, and two computers opened this application from the network drive, is there any way to make the program to communicate to each other in terms of updating the data? like if I checked-in a guest in room 301, the other program on the other computer will updated its room status to occupied.

I'm using CFile & CArchive for storing the information in a file.

I've tried using a timer that continually reads the file but obviously this will return an error eventually.

I've tried SendMessage() with HWND_BROADCAST using 2 GUIDs to make sure the other application is the only application that receives the message. This works perfectly when accessed from the same computer but wont work if the application is accessed from two computers.

Is there any other way?
thanks!
Posted
Updated 23-Dec-09 15:46pm
v2

Welcome to network programming. You'll need to use client/server architechture.

The clients are just front-end programs, and the server is the real meat that will have all the information needed. When a client needs to know something, it should ask the server. And when a client does something, it needs to let know of the server.

If you're using MFC, you could use the socket classes provided by MFC - CSocket and CAsyncSocket (see, for instance, Windows Sockets in MFC). There are many articles on socket programming on this site. Just do a search, and readup on that. Post a query here if you get stuck somewhere.

Hope that helps. :)
 
Share this answer
 
v2
wrote:
I'm using CFile & CArchive for storing the information in a file.


IOstreams are better, but that will work.

wrote:
I've tried SendMessage() with HWND_BROADCAST using 2 GUIDs to make sure the other application is the only application that receives the message. This works perfectly when accessed from the same computer but wont work if the application is accessed from two computers.


SendMEssage is local only. you'll need to maintain a network communication, which I don't think C++ or MFC supports natively. Some inter process communication mechanisms may work over a network. You could also have a seperate service that watches a folder and when a file is written there, decodes it into messages which it sends to your main app, to act accordinlgy.
 
Share this answer
 

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