/// <summary> /// /// </summary> private void networkListen() { while (true) { // Buffer byte[] buffer = new byte[1024]; // Request header string requestHeader = String.Empty; // Listen for client using (Socket client = serverSocket.Accept()) { // Chunk data in while (client.Poll(2 * 1000000, SelectMode.SelectRead)) { // Clear out the buffer Array.Clear(buffer, 0, buffer.Length); // Get bytes from client client.Receive(buffer); // Append to request header requestHeader += new String(Encoding.UTF8.GetChars(buffer)); // If we found the end of the header, quit if (requestHeader.IndexOf("\r\n\r\n") > -1) { break; } } // Call the new HTTP request method NewHttpRequest(new HttpRequest(new HttpRequestHeader(requestHeader), client)); // Ditch the client client.Close(); } } }
Sometimes, Socket.Accept will throw an Exception. It's only sometimes, and it's immediately after the program starts.
I do have a busy loop in to wait for an IP to be assigned, but otherwise I can't figure out what going on here. Ideas?