Dataexchange between C# Server (Not Webserver) and PHP

943 views Asked by At

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.


2

There are 2 answers

2
Hannes de Jager On BEST ANSWER

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.

1
Andrew Sledge On

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.