Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When ready, open the server.cs, which is provided in the lab of this module, and modify it such that the message received from a client

When ready, open the server.cs, which is provided in the lab of this module, and modify it such that the message received from a client is not only displayed but also processed further. With this modification, the server displays the original message in one line, then it extracts all vowels (i.e., a, e, i, o, u) from the message and displays only the extracted vowels in another line. For example, if the client sends "ENB301a Tampa Florida USA", the server will copy to display it first and prints another line "[Server] Vowel characters detected = .....EaaaoiaUA". All vowels should be printed as they are without spaces. If a vowel character is in upper case in the original message, it should also be printed in upper case.

Server.cs

/* * C# Program to Establish Client Server Relationship */

//SERVER PROGRAM using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets;

namespace MyServer4104 { class Program { static void Main(string[] args) { //Declare the server queue: TcpListener serverQueue = null; try { // 1. Set up an IP object to represent one IP of your computer: IPAddress ipAd = IPAddress.Parse("127.0.0.1"); //Or the wired or WiFi IP of your computer // 2. Create the queue to listen for and accept incoming connection requests: serverQueue = new TcpListener(ipAd, 63000); // TCP port numbers range from 0 to 65536, i.e., 16 bits. // DO NOT use a port number in the range from 0 to 1023. They are the well-known ports or // system ports. // Port numbers from 1024 to 49151 are the registered ports. You may use them like 63000 // if they are not registered or registered but the program is not running in your computer. // Use the Start method to begin listening for incoming connection requests. // It will queue incoming connections until the Stop method is called. serverQueue.Start(); Console.WriteLine("[Server] The server is running at port 63000"); Console.WriteLine("[Server] So, the server's local end point is: " + serverQueue.LocalEndpoint); Console.WriteLine("[Server] Waiting for a client's connection........"); // 3. Pull a connection from the queue to make a socket: Socket aSocket = serverQueue.AcceptSocket(); Console.WriteLine(" [Server] Connection accepted from a client " + "whose end point is: " + aSocket.RemoteEndPoint); // 4. Get the message sent by client through socket: byte[] incomingDataBuffer = new byte[1000]; char aChar = new char(); int totalBytes = aSocket.Receive(incomingDataBuffer); // Receive from client, byte by byte // 5. Display the received message: Console.WriteLine("[Server] Message of client recieved"); for (int i = 0; i < totalBytes; i++) { aChar = Convert.ToChar(incomingDataBuffer[i]); Console.Write(aChar); } // 6. Tell client its message was received: ASCIIEncoding ascii = new ASCIIEncoding(); Console.Write(" [Server] Hit 'Enter' to send acknowledgement to clicnt and end the session...."); Console.ReadLine(); aSocket.Send(ascii.GetBytes("[Server] Your message was recieved.")); // Send to client, byte by byte through socket aSocket.Close(); } catch (SocketException se) { Console.WriteLine(" [Server] Socket Error Code: " + se.ErrorCode.ToString()); Console.WriteLine(" " + se.StackTrace); } finally { // 7. Stop listening request and recycle the queue: serverQueue.Stop(); Console.WriteLine(" Bye!"); } } } }

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

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions