C# Program that Accepts an Employee Name From Client and Display the Job Title using XML
In this program, using client, employee name is being accepted and then it passes the employee job using XML. On the client-side, we are using a while loop and at each iteration, we are creating a value for the ‘object’ variable using the TcpClient() method. This is specifically used to provide client connections for TCP network services. Also, we have used the GetStream() method that returns the NetworkStream which is used for the transmission of data(send and receive).
We have assigned the value of the AutoFlush() method as true. This specifically marks the value that indicates whether the StreamWriter would flush the buffer to the specified stream after every call to StreamWriter.Write. We have used a while loop and at each step of the iteration, we are reading the name of the employee.
Here, the close() method terminates the current stream and free any resources (such as sockets and file handles) linked with the current stream. On the server side, we have used AcceptSocket() function that accepts the connection request that is pending. Again, we have used the while loop to read the name of the employee.
To check whether the name variable is empty or null we have used the If condition statement. To obtain the AppSettingsSection data we have used AppSettings for the current application’s default configuration.
To check whether the value of the ‘job’ variable is equal to null we are have used another if condition. If this condition evaluates true then we have marked the value of the ‘job’ variable as “Invalid Employee”. To write specified data we are using WriteLine() method. The current line terminator is then used to the standard output stream. Eventually, the name of the employee is given on the client side and the corresponding employee job has been printed.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key = "Bhuwanesh" value="Developer"/> <add key = "Harshit" value="Tester"/> </appSettings> </configuration>