usingSystem;usingSystem.IO;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Text;classTcpPacketDemo{staticbyte[]buffer=newbyte[1024];staticintpacketSize=4;staticvoidMain(string[]args){TcpListenerlistener=newTcpListener(IPAddress.Any,8080);listener.Start();Console.WriteLine("Server started on port 8080");while(true){TcpClientclient=listener.AcceptTcpClient();Console.WriteLine("Client connected");NetworkStreamstream=client.GetStream();while(true){intbytesRead=stream.Read(buffer,0,packetSize);if(bytesRead==0){Console.WriteLine("Client disconnected");break;}intpacketLength=BitConverter.ToInt32(buffer,0);byte[]packet=newbyte[packetLength];bytesRead=0;while(bytesRead<packetLength){intbytesToRead=packetLength-bytesRead;if(bytesToRead>buffer.Length){bytesToRead=buffer.Length;}intn=stream.Read(buffer,0,bytesToRead);if(n==0){Console.WriteLine("Client disconnected");break;}Array.Copy(buffer,0,packet,bytesRead,n);bytesRead+=n;}Console.WriteLine("Received packet: "+Encoding.ASCII.GetString(packet));byte[]response=Encoding.ASCII.GetBytes("Packet received");byte[]responseLength=BitConverter.GetBytes(response.Length);stream.Write(responseLength,0,packetSize);stream.Write(response,0,response.Length);stream.Flush();}client.Close();}}}