Modify it such that the message received from a client is an
Modify it such that the message received from a client is analyzed. The server still display the original message but it also extracts all vowels (i.e., a, e, i, o, u) from the message, put them together and displays them in another 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!\");
}
}
}
}
Solution
we need to add another point ie point 6 for getting vowels and then printing them in order how they are coming from buffer. a if condition will do the work for finding the vowel
//get all vowels from server message
Console.WriteLine(\"[Server] vowel character detected\");
for (int i = 0; i < totalBytes; i++)
{
aChar = Convert.ToChar(incomingDataBuffer[i]);
if (aChar == \'a\' || aChar == \'A\' || aChar == \'e\' || aChar == \'E\' || aChar == \'i\' || aChar == \'I\' || aChar ==\'o\' || aChar==\'O\' || aChar == \'u\' || aChar == \'U\')
printf(\"%c\", aChar);
else
//do nothing
}
this the code modified in the exsisting program full program is stated below
/*
* 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);
}
//get all vowels from server message
Console.WriteLine(\"[Server] vowel character detected\");
for (int i = 0; i < totalBytes; i++)
{
aChar = Convert.ToChar(incomingDataBuffer[i]);
if (aChar == \'a\' || aChar == \'A\' || aChar == \'e\' || aChar == \'E\' || aChar == \'i\' || aChar == \'I\' || aChar ==\'o\' || aChar==\'O\' || aChar == \'u\' || aChar == \'U\')
printf(\"%c\", aChar);
else
//do nothing
}
// 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!\");
}
}
}
}



