Note that there are some explanatory texts on larger screens.

plurals
  1. POc# If statement always returns false
    text
    copied!<p>I'm currently developing a small server/client application for a personal project. The server is meant to be run in Linux under Mono while the client is being run from a Windows PC. </p> <p>I have an issue where I am passing data to the server (In this case string value of "on" and "off") however an if statement is always returning a false value.</p> <p>The code from the server is as follows</p> <pre><code>public void startServer() { TcpListener listen = new TcpListener(serverIP, 10000); listen.Start(); Console.Clear(); Console.WriteLine("IP Address = {0}", serverIP.ToString()); Console.WriteLine("Server is listening for connection"); Socket a = listen.AcceptSocket(); Console.WriteLine("Connection from {0}", a.RemoteEndPoint); ASCIIEncoding respond = new ASCIIEncoding(); a.Send(respond.GetBytes("You are connected to LED Control Server")); bool keepListening = true; while (keepListening) { byte[] b = new byte[1000]; a.Receive(b); Console.WriteLine("Message Received from {0}, string: {1}", a.RemoteEndPoint, recData(b)); string serverMsg = procIns(recData(b)); a.Send(respond.GetBytes(serverMsg)); } } private string recData(byte[] b) //receiving data from the client { int count = b.Length; string message = ""; for (int a = 0; a &lt; count; a++) { message += Convert.ToChar(b[a]); } return message; } private string procIns(string instruction) { string returnMsg; Console.WriteLine(instruction.ToLower()); if (instruction.ToLower() == "on") { FileGPIO gpio = new FileGPIO(); gpio.OutputPin(FileGPIO.enumPIN.gpio17, true); returnMsg = "GPIO 17 1"; } else if (instruction.ToLower() == "off") { FileGPIO gpio = new FileGPIO(); gpio.OutputPin(FileGPIO.enumPIN.gpio17, false); returnMsg = "GPIO 17 0"; } else { returnMsg = "Invalid Command"; } return returnMsg; } </code></pre> <p>The cause for the if statement in procIns method returning false is escaping me, if anyone could offer any advice I would appreciate it!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload