function UClientTh.Receive_Data():Integer;
var nByte : Integer;
Receive_Buff : array[0..1024] of char;
S_Str : string;
begin
FillChar(Receive_Buff, SizeOf(Receive_Buff), #0);
while True do
begin
SetTimeOut(5000);
while True do
begin
Application.ProcessMessages;
if Time_Out then
begin
F_Main.memo1.lines.add('THREAD RECV Time Out ');
Client_UDP.Free;
Result := -1;
exit;
end;
nByte := 0;
Client_UDP.ReadBuffer(Receive_Buff, nByte);
end;
Gs_Return_Value :=Recv_Data_Processing(StrPas(Receive_Buff));
if Gs_Return_Value = 9 then
begin
Result := 0;
exit;
end;
if Gs_Return_Value = -1 then
begin
Result := -1;
exit;
end;
end;
end;
쓰레드에서 UDP를 동적으로 생성시켜 준 후
서버로부터 받는 부분입니다.
시간을 정해 준후 5초 이상이 되도록 데이터가 오지 않으면
타임아웃시키구. UDP도 프리시켜주구요..
5초안에 데이터가 날라오면 제일 안쪽에 있는 루프를 빠져나와서
데이터 받는 펑션으로 가구요.
그런데 문제는 한번 날라온 자료를 다음 자료가 올때까지 계속해서
읽는다는겁니다.
한번 읽은 자료는 다시 읽을 필요가 없구.. 그런데.. 계속해서 다음 자료가
올때까지.. 그러니까. 다음 자료가 안오면 그 자료만 계속해서 읽게 되구
무한 루프에 빠지는데.. 어떻게 해야할지..
도와주세요.. 정중히 부탁드립니다.