Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Gpa.exe.config Modify the server.cs and client.cs programs for C# that will read Gpa.exe.config XML file , such that a client can enter a student ID

Gpa.exe.config

Modify the server.cs and client.cs programs for C# that will read Gpa.exe.config XML file, such that a client can enter a student ID like 'U101' and the server returns his/her major 'PHYSICS'. The client will automatically send the returned major back to the server in order to get the major's average GPA using the same XML file. Then, the client displays the major of the input student and the major's average GPA.

Client.cs

using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Net.Sockets;

namespace ClientSocket { class Program { static void Main(string[] args) { TcpClient client = new TcpClient("127.0.0.1", 2055); try { Stream s = client.GetStream(); StreamReader sr = new StreamReader(s); StreamWriter sw = new StreamWriter(s); sw.AutoFlush = true; Console.WriteLine(sr.ReadLine()); while (true) { Console.Write("Enter a book title: "); string title = Console.ReadLine(); sw.WriteLine(title); if (title == "") break; Console.WriteLine(sr.ReadLine()); } s.Close(); } finally { client.Close(); } } } }

Server.cs

//SERVER SIDE PROGRAM using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.IO; using System.Net; using System.Net.Sockets; using System.Configuration;

namespace ServerSocket { class Program { static TcpListener listener; const int LIMIT = 5; public static void Query() { while (true) { Socket soc = listener.AcceptSocket(); Console.WriteLine("Connected: {0}", soc.RemoteEndPoint); try { Stream s = new NetworkStream(soc); StreamReader sr = new StreamReader(s); StreamWriter sw = new StreamWriter(s); sw.AutoFlush = true; // enable automatic flushing sw.WriteLine("{0} books available", ConfigurationManager.AppSettings.Count); while (true) { string bookTitle = sr.ReadLine(); if (bookTitle == "" || bookTitle == null) break; string price = ConfigurationManager.AppSettings[bookTitle]; if (price == null) price = "Sorry, no such book!"; sw.WriteLine(price); } s.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Disconnected: {0}", soc.RemoteEndPoint); soc.Close(); } } static void Main(string[] args) { IPAddress ipAd = IPAddress.Parse("127.0.0.1"); listener = new TcpListener(ipAd, 2055); listener.Start(); Console.WriteLine("Server started, listening to port 2055"); for (int i = 0; i < LIMIT; i++) { Thread t = new Thread(new ThreadStart(Query)); t.Start(); Console.WriteLine("Server thread {0} started....", ++i); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago