파일을 다운로드하여 서버에 연결해야합니다. 연결에 실패하면 루프를 다시 시작합니다. 어떻게 든 while 루프는 파일을 계속 실행하고 다운로드합니다. 부울과 함께 뭔가 이상한 일이 발생한다고 생각합니다. Globals.sockRetry하지만 실제로 일어나는 일을 찾을 수 없습니다.while 루프가 중단 된 후에도 계속 실행됩니다.
public class Globals
{
public static string serverIp;
public static int serverPort;
public static int sockConn = 0;
public static bool sockRetry = false;
public static TcpClient client;
public static NetworkStream nwStream;
public static StreamReader reader;
public static StreamWriter writer;
}
static void connect(Globals g)
{
Globals.sockConn = 1;
try
{
Globals.client = new TcpClient(Globals.serverIp, Globals.serverPort);
Globals.nwStream = Globals.client.GetStream();
Globals.reader = new StreamReader(Globals.nwStream);
Globals.writer = new StreamWriter(Globals.nwStream);
Globals.sockConn = 2;
string inputLine;
while ((inputLine = Globals.reader.ReadLine()) != null)
{
// ParseMessage(Globals.writer, inputLine, g);
}
}
catch
{
Globals.sockRetry = true;
Globals.sockConn = 0;
return;
}
}
static void getInfo()
{
while (true)
{
try
{
WebRequest request = WebRequest.Create(INFO_HOST + INFO_PATH);
WebResponse response = request.GetResponse();
string content;
using (var sr = new StreamReader(response.GetResponseStream()))
{
content = sr.ReadToEnd();
}
string[] contentArray = content.Split(':');
string serverIp = contentArray[0];
string serverPortStr = contentArray[1];
int serverPort = 5000;
Int32.TryParse(serverPortStr, out serverPort);
Globals g = new Globals();
Globals.serverIp = serverIp;
Globals.serverPort = serverPort;
while (Globals.sockConn == 0)
{
if (Globals.sockRetry == false)
{
connect(g);
}
else
{
// error connecting
// wait and retry
Globals.sockRetry = false;
Thread.Sleep(60000);
break;
}
}
continue;
}
catch
{
// error downloading file
// wait and retry
Thread.Sleep(60000);
continue;
}
}
}
while 루프를 나가기위한 조건은 어디에 있습니까? 내가 볼 수 있듯이 while 루프는'continue'에서 끝나고 결코 빠져 나오지 못합니다. – OmniOwl
알다시피, 새 질문을 다시 게시하는 대신 이전 질문을 편집 할 수있었습니다. – stakx
다운로드가 성공하더라도 프로그램이 파일을 계속 다운로드한다는 의미입니까? 다운로드가 성공적 이었습니까? 성공 여부는 어떻게 확인 했습니까? – stakx