这是来自 Microsoft 套接字教程http://msdn.microsoft.com/en-us/library/6y0e13d3.aspx的示例
我有点困惑。第一个 while(true) 无限循环后面跟着第二个 4 行,但我们只使用一个 break 语句。在第二个 while 循环中使用 break 应该继续第一个 while 循环......不是吗? http://msdn.microsoft.com/en-us/library/6y0e13d3.aspx
while (true) {
Console.WriteLine("Waiting for a connection...");
// Program is suspended while waiting for an incoming connection.
Socket handler = listener.Accept();
data = null;
// An incoming connection needs to be processed.
while (true) {
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes,0,bytesRec);
if (data.IndexOf("<EOF>") > -1) {
break;
}
}
}