C# 服务器(不是 Web 服务器)和 PHP 之间的数据交换
我有一个持续运行的服务器程序(Linux 上的 C#/.NET 2.0,单声道),我想从 PHP 脚本连接到它以在网站上显示状态信息。
目的是创建一个(某种)实时浏览器游戏(无 Flash,无 Silverlight),我想使用 PHP 脚本从 C# 游戏服务器获取必要的信息,即当前单位位置、玩家资源、得分、可见地图信息每秒甚至更快地更新,但操作可能需要几个小时甚至几天(即研究可能需要一周才能完成)
是否有任何库可以让我轻松地在程序的这两部分之间传输信息?
我的想法:
使用嵌入式 WebServer 并通过 PHP SoapClient 进行连接。
有人有使用免费嵌入式 Web 服务器的经验吗(免费是因为游戏是免费的)?套接字编程和传输 JSON/XML/SOAP 块。
是否有任何简单的库用于 PHP/C# 的这种类型的网络通信,自动从套接字读取直到消息完成,然后将事件发送到游戏控制器?只需将每个用户和全局数据转储到数据库或 xml 文件中
最简单的解决方案,但恕我直言,扩展性不够。
你有什么建议?
提前致谢。
对于其他有类似问题的人的补充:
在发布此问题后进行了更多研究后,我偶然发现 .NET System.Net.HttpListener 甚至受 Mono 支持,所以我会 现在就用这个。它似乎拥有嵌入 WebServer 所需的一切 进入您正在运行的服务器。
i have a continously running Serverprogram (C#/.NET 2.0 on Linux with mono) and i want to connect to it from a PHP Script to display status informations on a WebSite.
The purpose is to create a (sort-of) Realtime Browsergame (No Flash, no Silverlight) and i want to use the PHP Script to get the necessary informations from the C# GameServer, i.e. current unit positions, player resources, score, visible map, etc. Informations update every second or even faster but actions might take hours or even days (i.e. research might take a week to complete)
Are there any libraries which allow me to easily transfer informations between those two parts of the program?
My thoughts:
Use an embedded WebServer and connect via PHPs SoapClient.
Does anyone have experience with a free embedded WebServer (free because the Game will be free)?Socket Programming and transfer chunks of JSON/XML/SOAP.
Are there any simple libraries for this type of network communication for PHP/C# that automatically reads from the socket until the message is done and then i.e. sends an event to the game controller?Simply Dump per-user and global Data into a Database or into xml files
Easiest solution but imho not scaleable enough.
What would you suggest?
Thanks in advance.
Addition for others having a similar Question:
After a little more research after posting this Question i stumbled upon
the .NET System.Net.HttpListener which is even supported by mono so i will
use this now. It seems to have everything required to embed an WebServer
into your running Server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将使用一个简单的嵌入式网络服务器,只使用 PHP Curl 扩展来与其交互 http: //php.net/manual/en/book.curl.php。对于嵌入式网络服务器,我开始寻找 codeplex,例如 http://www.codeplex.com/webserver。
I would use a simple embedded webserver and just use the PHP Curl extentions to interact with it http://php.net/manual/en/book.curl.php. For the embedded webserver I'd start looking on codeplex e.g. http://www.codeplex.com/webserver.
只需在 C# 服务器上运行一个简单的服务器,通过套接字从客户端 (PHP) 连接到它。您必须编写交互“规则”,但您可以避免 JSON/SOAP 等带来的开销。另一个解决方案是使用 XMLRPC 服务器。
Just run a simple server on the C# server, connect to it from your client (PHP) via a socket. You'll have to write the "rules" for interaction, but you can avoid the overhead that comes with JSON/SOAP, etc. Another solution is to use an XMLRPC server.