I have a socket server and am trying to receive a string from the client.
The client is perfect and when I use this
Socket s = myList.AcceptSocket(); Console.WriteLine("Connection accepted from " + s.RemoteEndPoint); byte[] b = new byte[100]; int k = s.Receive(b); Console.WriteLine(k); Console.WriteLine("Recieved..."); for (int i = 0; i < k; i++) { Console.Write(Convert.ToChar(b[i])); ASCIIEncoding asen = new ASCIIEncoding(); s.Send(asen.GetBytes("The string was recieved by the server.")); } All is okay and I get my string in the console.
But how can I get now my receive into a string so I can use it in a switch case?
Like this:
string action = Convert.ToChar(b[i]); Error:
The Name i isn't in the current context. its the only Error Message i get.
Convert.ToChar(b[i])and expect it to return a string in which the variableilooped through all the bytes of theb-array. Explicity create the loop variableiin aforstatement, otherwise the variable won't exist.string action = ""; for(int i=0; i < b.Length; i++) action += Convert.ToChar(b[i]);would fill theactionvariable appropiatly.for();?