Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of this project is to design and write a TCP client and a TCP serv

ID: 3533103 • Letter: T

Question

The objective of this project is to design and write a TCP client and a TCP server application in Visual C++.   The TCP client sofware will transmit a user entered packet of bytes to the TCP server software. It is recommended that all programs be done as Visual C++ console applications.


a) The TCP client application:

This application will open a socket on a remote host that is running the TCP application software. It will get the following information from the user prior to opening a connection to the remote host.

1. Destination socket port number

2. Destination host IP address

The application will open the connection to the remote host. If successful, it will prompt the user for data to send to the remote host. At the end of data entry, the application will send the packet to the remote host. The application will offer the option to the user to enter a new packet to send or exit the application. On exit, the application will perform a graceful shutdown of the socket connection prior to termination. The user interface for this application is left open to creativity.

a) The TCP server application:

This application will listen for data on a socket in host that is running this application. It will get the following information from the user prior to listening for data on that socket.

1.Socket port number to listen to.

The application will listen for data on the assigned socket port. If data is received, the application will display the data on the display in a suitable format. The application will also offer the user the option to exit the application. On exit, the application will perform a graceful shutdown of the socket connection prior to termination. The user interface for this application is left open to creativity.


Please I need full detail code!!!

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.Net.Sockets;

using System.Threading;

using System.IO;

namespace server

{

public class login

{

Socket s;

public login(Socket valueS)

{

s = valueS;

}

public void check()

{

try

{

byte[] uname = new byte[100];

byte[] pword = new byte[100];

int sizeuser = s.Receive(uname);

int sizepword = s.Receive(pword);

if (sizeuser > 0 && sizepword > 0)

{

Console.WriteLine("Recieved");

TextReader objTxtReader = new StreamReader("login.txt");

String username = objTxtReader.ReadLine();

String password = objTxtReader.ReadLine();

String test = ASCIIEncoding.ASCII.GetString(uname);

test = test.Substring(0, sizeuser);

if (username == (ASCIIEncoding.ASCII.GetString(uname)).Substring(0, sizeuser) && password == (ASCIIEncoding.ASCII.GetString(pword)).Substring(0, sizepword))

{

}

else

{

ASCIIEncoding asen2 = new ASCIIEncoding();

s.Send(asen2.GetBytes("0"));

}

}

}

catch(Exception e){ }

}

}


public class Program

{

static void Main(string[] args)

{

try

{

IPAddress ipAd = IPAddress.Parse("192.168.10.68");

TcpListener myList = new TcpListener(ipAd, 8002);

myList.Start();

Random randDouble = new Random();

double randValue;

Socket s = myList.AcceptSocket();

login objLogin = new login(s);

Thread thdLogin = new Thread(new ThreadStart(objLogin.check));

thdLogin.Start();

thdLogin.Join();

while (true)

{

randValue = randDouble.NextDouble();

Console.WriteLine(randValue);

Thread.Sleep(500);

ASCIIEncoding asen = new ASCIIEncoding();

String strRandValue = randValue.ToString();

byte[] msg = asen.GetBytes(strRandValue);

s.Send(msg);

}

s.Close();

}

catch (Exception e)

{

Console.WriteLine("Error..... " + e.StackTrace);

}

}

}

}

client code

using System.Collections.Generic;

using System;

using System.IO;

using System.Net;

using System.Text;

using System.Net.Sockets;

using System.Threading;

namespace client

{

class Program

{

static void Main(string[] args)

{

try

{

TcpClient tcpclnt = new TcpClient();

Console.WriteLine("Connecting.....");

String username=null;

String password= null;

tcpclnt.Connect("192.168.10.68", 8002);

Console.WriteLine("Connected");

Console.WriteLine("Enter Username");

username = Console.ReadLine();

Console.WriteLine("Enter Password");

// password = Console.ReadLine();

ConsoleKeyInfo key;

do

{

key = Console.ReadKey(true);

if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)

{

password += key.KeyChar;

Console.Write("*");

}

else

{

if (key.Key == ConsoleKey.Backspace && password.Length > 0)

{

password = password.Substring(0, (password.Length - 1));

Console.Write(" ");

}

}

}while(key.Key!=ConsoleKey.Enter);

Console.Write(" ");

Stream stm = tcpclnt.GetStream();

ASCIIEncoding uname = new ASCIIEncoding();

byte[] byteUsername = uname.GetBytes(username);

ASCIIEncoding pword = new ASCIIEncoding();

byte[] bytePword = uname.GetBytes(password);

stm.Write(byteUsername, 0, byteUsername.Length);

stm.Write(bytePword, 0, bytePword.Length);

byte[] byteMsg = new byte[100];

int length = stm.Read(byteMsg, 0, 100);

while (length>1)

{

for (int i = 0; i < length; i++)

Console.Write(Convert.ToChar(byteMsg[i]));

Console.WriteLine(" ");

length = stm.Read(byteMsg, 0, 100);

}

if (length == 1)

{

Console.WriteLine("Invalid username or password");

}

tcpclnt.Close();

String str1 = Console.ReadLine();

}

catch (Exception e)

{

Console.WriteLine("Error..... " + e.StackTrace);

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote