跨任何操作系统和操作系统的进程间通信最简单的方法是什么?语言
编程竞赛 (代码战争)我想设置它,将游戏状态作为 xml 文件传递给 AI,并且 AI 会以 xml 文件的形式进行回复,然后返回到我的应用程序。然后,参赛的每个团队都可以使用语言和方法来实现他们的人工智能。他们最满意的操作系统。
性能并不重要。它是两个来回传递的小 xml 文件(我说的是文件,但它可能只存在于内存中)。但简单性很重要,这样才能快速、轻松地以任何语言实现客户端 (AI)。
我想在服务器上打开一个 TCP 套接字,发送状态 xml 文件,然后进入接收模式等待轮流 xml 文件。而且我还会在等待时设置一个超时,这样如果我在一秒钟内没有收到答复,我就会为他们设置默认轮次。
在客户端,它等待 TCP 套接字连接,读入 xml 文件,确定轮次,然后将 xml 文件写回。
这是让客户可以用大多数语言快速轻松地编写的东西的最佳方式吗?
更新:这将使每个玩家使用不同的机器。必须允许这一点,因为有些人喜欢 Windows,有些人喜欢 Linux。它使这个过程变得更容易。
谢谢-戴夫
For a programming competition (code war) I want to set it up where I pass the game state to an A.I. as an xml file and that A.I. replies with it's turn in an xml file it returns to my app. Every team in the competition can then implement their A.I. using the language & O/S they are most comfortable with.
Performance is not critical. It is two small xml files (I say file but it will probably only exist in memory) that get passed over and back. But simplicity is important so that it's quick and easy to implement the client (A.I.) side in any language.
I am thinking that on the server I open a TCP socket, send the state xml file, then go into receive mode waiting for the turn xml file. And I would also have a time-out on the wait so that if I received no answer in a second, I put in a default turn for them.
And on the client side it waits for a TCP socket connection, reads the xml file in, determine its turn, and writes the xml file back out.
Is this the best way to have something where a client can be quickly and easily written in most any language?
Update: This will have each player on a different machine. Have to allow this as some prefer Windows and some Linux. And it makes the process easier.
thanks - dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的客户端和服务器在同一台计算机上运行,则对 IPC 使用 stdin/stdout 可能会更容易。服务器将执行 AI 进程,将 XML 文档写入 AI 标准输入,然后等待 AI 标准输出上的响应。
如果您的 AI 需要长时间运行(例如,为了维护大量持久状态),那么您可以将 AI 分为两部分,一部分是“常驻”部分,另一部分是运行的接口组件游戏过程中的每一回合。接口组件可以通过最适合该语言的任何机制(REST、共享内存、消息传递等)与驻留部分进行通信。
If your client and server are running on the same machine, it might be even easier to use stdin/stdout for the IPC. The server would execute the AI process, write an XML document to the AI stdin, then wait for a response on the AI stdout.
If your AI needs to be long-running (to maintain a lot of persistent state, for example), then you could split the AI into two parts, one that is "resident" and the other that is an interface component that is run for each turn by the game process. The interface component could communicate with the resident part by whatever mechanism is most suitable for the language (REST, shared memory, message passing, whatever).
无论您使用什么语言,您都需要一个 XML 包。
您也可以使用 TCP/IP 上的 HTTP 包 - 当然,它不需要使用端口 80。这很可能是与不同语言的“标准”或“接近标准”的最佳支持的组合。
You will need an XML package in whatever languages you are using.
You might use an HTTP over TCP/IP package too - it need not be using port 80, of course. That might well be the combination with the best support available as 'standard' or 'near standard' for different languages.