Instead of trying to get your server-side PHP script to send data to a C # program, which will give you a bunch of headaches, why not write something in a PHP script, which, given a specific request to the page, puts the current queues in the queue? Then the C # program can just do a WebRequest on the page and get its instructions.
For instance:
== php script ==
<?php //main execution. process_request(); function process_request() { $header = "200 OK"; if (!empty($_GET['q']) && validate_request()) { switch ($_GET['q']) { case "get_instructions": echo get_instructions(); break; case "something_else": //do something else depending on what data the C
Now to actually retrieve data from the query:
== C # code code ==
private string QueryServer(string command, Uri serverpage) { string qString = string.Empty; HttpWebRequest qRequest = (HttpWebRequest)HttpWebRequest.Create(serverpage.AbsoluteUri + "?q=" + command); qRequest.Method = "GET"; qRequest.UserAgent = "MyAppName/1.1 (Instruction Request)"; using (HttpWebResponse qResponse = (HttpWebResponse)qRequest.GetResponse()) if (qResponse.StatusCode == HttpStatusCode.OK) using (System.IO.StreamReader qReader = new System.IO.StreamReader(qResponse.GetResponseStream())) qString = qReader.ReadToEnd().Trim(); ; return qString; }
This is a rough template with minimal error handling, I hope this is enough to get you started.
EDIT: Woops forgot to include a usage example:
MessageBox.Show(QueryServer("get_instructions", new Uri("http://localhost/interop.php")));
source share