将消息发送到网络上的另一个应用程序 [英] Send messages to another application on a network

查看:110
本文介绍了将消息发送到网络上的另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是编程的初学者,并且已经学习了一段时间.我正在尝试制作一个处理数据的应用程序,尤其是关于旅馆数据的数据,例如客人姓名,到达日期等.该应用程序将用于旅馆接待员,这样他们就可以知道哪个房间是空房间或有人住了,并可以欣赏风景来宾名单等...

所以我的问题是,如果将应用程序放在网络驱动器中,并且两台计算机从网络驱动器中打开了该应用程序,是否有任何方法可以使程序在更新数据方面彼此通信?就像我在301房间登记入住时一样,另一台计算机上的其他程序会将其房间状态更新为已占用.

我正在使用CFile和CArchive将信息存储在文件中.

我尝试使用一个计时器来连续读取文件,但是显然这最终会返回错误.

我已经尝试使用2个GUID与HWND_BROADCAST一起使用SendMessage(),以确保另一个应用程序是接收消息的唯一应用程序.当从同一台计算机访问时,此方法非常有效,但如果从两台计算机访问该应用程序,则将无法正常工作.

还有其他方法吗?

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!

推荐答案

欢迎使用网络编程.您需要使用客户端/服务器架构.

客户端只是前端程序,而服务器才是真正的肉,它将具有所需的所有信息.当客户需要了解某些内容时,应询问服务器.当客户端执行某项操作时,它需要告知服务器.

如果使用的是MFC,则可以使用MFC提供的套接字类-CSocketCAsyncSocket(例如,参见
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. :)


写道:​​

我使用CFile&用于将信息存储在文件中.

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



IOstream更好,但这将起作用.



IOstreams are better, but that will work.

写道:​​

我已经尝试使用2个GUID与HWND_BROADCAST一起使用SendMessage(),以确保另一个应用程序是接收消息的唯一应用程序.当从同一台计算机访问时,此方法非常有效,但如果从两台计算机访问该应用程序,则将无法正常工作.

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仅是本地的.您将需要维护网络通信,我认为C ++或MFC本身不支持.某些进程间通信机制可以在网络上工作.您还可以使用单独的服务来监视文件夹,然后在将文件写入其中时将其解码为将其发送到主应用程序的消息,以进行协调.



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.


这篇关于将消息发送到网络上的另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆