F
Fly_away
Unregistered / Unconfirmed
GUEST, unregistred user!
用TIdHTTP在多线程里发送数据,发了一会就报"Socket Error # 10048 Address already in use." ( 积分: 100 )<br />请问我用TIdHTTP在多线程中网一地址POST数据,每次POST1064字节,但发了一阵子后就会报
"Socket Error # 10048 Address already in use."不知怎么解决.
好象是说地址已经在使用,但为什么会发了一阵子后才报呢?
附上线程里的代码:
while (i <> iCount) do
begin
msSend.Clear;
rs.Clear;
Fms.Position := i * MainForm.iPerTransSize;
//取到块头信息
iTemp := FiBigBlockNO * FiCountBlock + i ;
msHead := TStringStream.Create(MainForm.getHead(iTemp));
msSend.CopyFrom(msHead, HttpUploadUnit.HEADSIZE);
msSend.Position := HttpUploadUnit.HEADSIZE;
msHead.Free;
//每次发送的内容
if(i = iCount - 1) then
msSend.CopyFrom(Fms, Fms.Size - i * MainForm.iPerTransSize)
else
msSend.CopyFrom(Fms, MainForm.iPerTransSize);
try
//数据发送
idHTTPPost.Post(FstrPostUrl, msSend, rs);
//如果返回值正确,则发送下一块数据
if(getResult(rs) = '1') then
begin
Inc(i);
Synchronize(UpdateProgressBar);
end
else
begin
inc(iErrorCount);
if(iErrorCount > 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
Exit;
end;
end;
except
inc(iErrorCount);
if(iErrorCount > 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
MainForm.ThreadIsOk[FiBigBlockNO] := false;
Exit;
end;
end;
end;
MainForm.ThreadIsOk[FiBigBlockNO] := true;
"Socket Error # 10048 Address already in use."不知怎么解决.
好象是说地址已经在使用,但为什么会发了一阵子后才报呢?
附上线程里的代码:
while (i <> iCount) do
begin
msSend.Clear;
rs.Clear;
Fms.Position := i * MainForm.iPerTransSize;
//取到块头信息
iTemp := FiBigBlockNO * FiCountBlock + i ;
msHead := TStringStream.Create(MainForm.getHead(iTemp));
msSend.CopyFrom(msHead, HttpUploadUnit.HEADSIZE);
msSend.Position := HttpUploadUnit.HEADSIZE;
msHead.Free;
//每次发送的内容
if(i = iCount - 1) then
msSend.CopyFrom(Fms, Fms.Size - i * MainForm.iPerTransSize)
else
msSend.CopyFrom(Fms, MainForm.iPerTransSize);
try
//数据发送
idHTTPPost.Post(FstrPostUrl, msSend, rs);
//如果返回值正确,则发送下一块数据
if(getResult(rs) = '1') then
begin
Inc(i);
Synchronize(UpdateProgressBar);
end
else
begin
inc(iErrorCount);
if(iErrorCount > 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
Exit;
end;
end;
except
inc(iErrorCount);
if(iErrorCount > 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
MainForm.ThreadIsOk[FiBigBlockNO] := false;
Exit;
end;
end;
end;
MainForm.ThreadIsOk[FiBigBlockNO] := true;