Skip to main content
Topic: C# GUI interface to Web Server (Read 2200 times) previous topic - next topic

C# GUI interface to Web Server

Having great fun (and learning) from the Web Server platform - here on my bench for the last 4 days :), my thoughts are now turning towards a Windows GUI interface to toggle LED2, plus anything else I hang off the header.

I’m guessing a GUI button could ‘talk’ to the server via http, has anyone tried this?
Has anyone any pointers as how to implement this?

At the moment I have a new C# project started, a single button on Form1, but have NO idea what needs to go into the event handler for the button :)

Regards
Kevin

Re: C# GUI interface to Web Server

Reply #1
you could get a minimalist pipe running on a nonstandard port to input commands to the web server

Re: C# GUI interface to Web Server

Reply #2
Update (& a happy man)....

OK I now have a very basic version working, below is the code for the button click event handler:

 private void button1_Click(object sender, EventArgs e)
        {
          // In this method you need to set up an event
            int count;
            byte[] buffer = new byte[8192];
           
          // create the request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.0.5/leds.cgi?led=1");
 
          // send request & get a response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

          // process the response
            Stream responseStream = response.GetResponseStream();
            count = responseStream.Read(buffer, 0, buffer.Length);

            response.Close();

        }

Now I can toggle LED2 via a simple windows application. The learning continues :)

Regards
Kevin