我有一个套接字服务器,正在尝试从客户端接收一个字符串。
客户端是完美的,当我使用它时
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."));
}
Run Code Online (Sandbox Code Playgroud)
一切正常,我在控制台中得到了我的字符串。
但是我现在如何将我的接收放入一个字符串中,以便我可以在开关盒中使用它?
像这样:
string action = Convert.ToChar(b[i]);
Run Code Online (Sandbox Code Playgroud)
错误:
Name i 不在当前上下文中。这是我收到的唯一错误消息。