在这个无限循环中应该有2个break语句

iAt*_*_it 2 c#

这是来自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;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

rhu*_*hes 7

你是对的.此示例中的外部循环不应该退出.这旨在不断寻找新的连接.服务器倾向于遵循这种基本模式.