End Google Ads 201810 - BS.net 01 --> My current code works fine, but I've encountered a problem. When a client connects to the TCP server, and they type a message it works the first time, but if its entered again, it just gives you the else. So lets say I typed shutdown in the client console. It would return Command Recieved, Initiating Shutdown. But if I try it again, it just gives me the else message. Its like its not cycling through the if statement again. What kind of code should I use to solve this issue?

Here is the code:


/*

C# TCP
by Joshua Garrett

*/


using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class Server
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7557);
UdpClient newsock = new UdpClient(ipep);

Console.WriteLine("Waiting for a client...");

IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

data = newsock.Receive(ref sender);

Console.WriteLine("Connection received from {0}", sender.ToString());

string welcome = "OpticVPS Remote Administration"; //where?
data = Encoding.ASCII.GetBytes(welcome);
newsock.Send(data, data.Length, sender);

while (true)
{
data = newsock.Receive(ref sender);


if (Encoding.ASCII.GetString(data, 0, data.Length) == "help")
{
string okay = "You can use the following commands";

Console.WriteLine("Help List Accessed By: {0}", sender.ToString());

data = Encoding.ASCII.GetBytes(okay);
newsock.Send(data, data.Length, sender);
}
else if (Encoding.ASCII.GetString(data, 0, data.Length) == "shutdown")
{
string shutdown = "Command Received, Shutting Down Now";

Console.WriteLine("Shutdown Issued - {0}", sender.ToString());

data = Encoding.ASCII.GetBytes(shutdown);
newsock.Send(data, data.Length, sender);


}
else
{
string err = "Command Not Found [End Of Line]";

Console.WriteLine("Command Error - {0}", sender.ToString());

data = Encoding.ASCII.GetBytes(err);
newsock.Send(data, data.Length, sender);

}
// newsock.Send(data, data.Length, sender);
}
}

}

[X] 100% HTML
[ ] 100% PHP
[ ] 100% C#