C# Project on Classroom Voting Application

This project creates an HTTP Server on a Windows PC. The server presents an html page to a connecting client. The page contains html and javascript for communication with the server. The server is capable of serving json to ajax requests coming from the html page. A mobile phone can be used to connect to the application. The phone must be on the same wifi network. Let's see the basic pre-requisites and the broader function now.
(Rev. 20-Nov-2022)

Categories | About |     |  

Parveen,

The Pre-requisites

First of all you will need a computer running windows 10. Mac and linux computers are not supported.

The computer must be connected to a wifi network. Internet is not required.

You will also need a phone or another computer on the same network. This device will be used for voting purposes. An ordinary wifi network easily supports about 200 users. So this application is more than sufficient for a big size classroom.

Video Explanation (see it happen!)

Please watch the following youtube video:

Compile the Project

Download the visual studio project from the downloads attached to this tutorial.

Compile the application and ensure that it compiles successfully. You should have the latest visual studio installed on your computer.

If everything goes right then the project should be compiled to a debug directory as you are seeing here. Right click the executable and run it as administrator. This permission is required because the application creates a server on the machine.

A console window opens because this is a C# console project. You will see a message of database migrations. The migrations will be applied the first time you run this application.

The console also shows the IP address of the server so that other users on the same network can communicate with it. You can even fix this IP address by using the control panel of your PC - but we haven't done that.

Next open a browser on the same computer and type - http localhost 8090. The port we shall is use is 8090. If it doesn't work you can try the next number. If that doesn't work try any port in the 50000 series.

Please note that https will not work because a secure server needs extra work, which is not required in our case.

A log of messages begins to appear in the console. This log shows the requests as they are being served. A home page for html and an image file of png type is being shown as you see.

The browser presents a question alongwith any images. It presents four options. Please note that all this is pure HTML, CSS and javascript story. So it can be moulded in whatever way you like.

Two boxes are provided - one for the user ID and the other for the password. These boxes can be used for authentication of your student. We are not going to make any authentication in this code, so you are free to type anything you want in these boxes.

We have added some client side validation also. If a student makes no choice, or leaves his user-id and password, then an error message is shown in red color.

Next the student chooses the "b" option and types any text for login and password.

When he clicks the "Vote" button, an AJAX request carries his data to the server. The server acknowledges his vote in the database and sends a summary of percentage votes polled by other users.

Please again note that this is just an indicator. You can use the application in any other way - for example - you can use it in a retail shop for obtaining registration of your customers, or for presenting a shopping cart to them.

Running on a Mobile Phone

This server can serve requests from a mobile phone also. A user has to type the same address as shown in the console. We shall later learn how to open a port on a pc so that other phones can access it.

The user is presented an error message if he doesn't make any choice.

And he is shown the complete statistics if his vote is accepted on the PC.

In the next tutorials we learn about the source code. Thanks!


This Blog Post/Article "C# Project on Classroom Voting Application" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.