I am writing a c# program which will recieve a message from a server, the problem it recieves the byte from the message but does not read the byte. It instead reads "recieved command = system.byte []. Below is the client code
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect(RecieveIP.Text, 8001); // use the ipaddress as in the server program
MessageBox.Show("Connected");
Console.Write("Enter the string to be transmitted : ");
Stream stem = tcpclnt.GetStream();
MessageBox.Show("Listening for information......");
byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToString(bb));
string toattk = bb.ToString();
MessageBox.Show("Recieved Command = " + toattk);
Sorry for the incorrect code formatting, am typing from a phone.
But i am wondering why it would be showing this instead of the decoded message? I can add the server code if necessary. The computers do successfully connect.
Edit:
So the edits worked, thank you! But I am trying to code so that a certain code will execute if the recieved message equals "g". Despite that the strings match, the if then statement does not execute. I am wondering why that might be? Here is the code? Thanks.
byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToString(bb));
string atk = Encoding.ASCII.GetString(bb);
MessageBox.Show("Recieved Command " + atk);
if (atk == "g")
{
MessageBox.Show("information received.");
search.RunWorkerAsync();
}