Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7679685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:56:06+00:00 2026-05-31T17:56:06+00:00

I am writing a program on a pc that is controlled via a php

  • 0

I am writing a program on a pc that is controlled via a php script on a server. I am currently using php to ftp a file back and forth and using the c# to read the file and execute commands based on the data in the file. However this is not an ideal solution.

I would like to see a tutorial or example on how to use php to send data to a c# program pver sockets.

Example of data I would like to send

1:control1
1:control2
1:control3
0:control4
0:control5

Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:56:07+00:00Added an answer on May 31, 2026 at 5:56 pm

    Rather than try and get your server-sided PHP script to send data to the C# program, which will give you a heap of headaches, why not write something on the PHP script that, given a specific request to the page, outputs the currently queued instructions? The C# program can then just make a WebRequest to the page and receive its instructions.

    For example:

    == 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# program requested.
                        break;
                    default:
                        $header = "403 Forbidden"; //not a valid query.
                        break;
                }
            }
            else { $header = "403 Forbidden"; } //invalid request.
            header("HTTP/1.1 $header");
        }
    
        function validate_request()
        {
            //this is just a basic validation, open to you for how you want to validate the request, if at all.
            return $_SERVER["HTTP_USER_AGENT"] == "MyAppName/1.1 (Instruction Request)";
        }
    
        function get_instructions()
        {
                        //pseudo function, for example purposes only.
            return "1:control1\n1:control2\n1:control3\n0:control4\n0:control5";
        }
    ?>
    

    Now to actually retrieve data from the request:

    == C# Client 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, hopefully it’s enough to get you started.

    EDIT: Woops, forgot to include an example usage:

    MessageBox.Show(QueryServer("get_instructions", new Uri("http://localhost/interop.php")));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read input via stdin, so I have the
I am writing a program that creates an image file. I want the original
Currently I am writing a program that must iterate through and arraylist inside of
I am writing a program that will read in a list of names with
HI I'm writing a program that acts as a server and has the ability
I'm writing a program that basically perform server-client relationship. When i run my client
I have tried writing program that plays a sound file but have been unsuccessful
I am writing a program that gets a HTML file in Android and I
I'm writing a program that needs to watch for file system events on multiple
I am writing a program that takes in an input file from the user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.