Question
open the server.cs , which is provided in the lab part of this module, and modify it such that the message received from a client
open the server.cs, which is provided in the lab part of this module, and modify it such that the message received from a client is not only displayed but also processed further. After displaying the received message, the server extracts all vowels (i.e., a, e, i, o, u) from the message and displays them together in a second line.
For example, if the client send "ENB301a Tampa Florida USA", the server displays it first as before, but it prints another line "[Server] Vowel characters detected = .....EaaaoiaUA". All vowels are collected together with upper or lower case of each character being preserved.
/*
* 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started