用TIdHTTP在多线程里发送数据,发了一会就报"Socket Error # 10048 Address already in use."

  • 主题发起人 主题发起人 Fly_away
  • 开始时间 开始时间
F

Fly_away

Unregistered / Unconfirmed
GUEST, unregistred user!
用TIdHTTP在多线程里发送数据,发了一会就报&quot;Socket Error # 10048 Address already in use.&quot; ( 积分: 100 )<br />请问我用TIdHTTP在多线程中网一地址POST数据,每次POST1064字节,但发了一阵子后就会报
&quot;Socket Error # 10048 Address already in use.&quot;不知怎么解决.
好象是说地址已经在使用,但为什么会发了一阵子后才报呢?
附上线程里的代码:
while (i &lt;&gt; 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 &gt; 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
Exit;
end;
end;
except
inc(iErrorCount);
if(iErrorCount &gt; 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
MainForm.ThreadIsOk[FiBigBlockNO] := false;
Exit;
end;
end;
end;
MainForm.ThreadIsOk[FiBigBlockNO] := true;
 
请问我用TIdHTTP在多线程中网一地址POST数据,每次POST1064字节,但发了一阵子后就会报
&quot;Socket Error # 10048 Address already in use.&quot;不知怎么解决.
好象是说地址已经在使用,但为什么会发了一阵子后才报呢?
附上线程里的代码:
while (i &lt;&gt; 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 &gt; 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
Exit;
end;
end;
except
inc(iErrorCount);
if(iErrorCount &gt; 2) then
begin
MainForm.memo1.Lines.Add('线程' + IntToStr(FiBigBlockNO) + '出错!');
MainForm.ThreadIsOk[FiBigBlockNO] := false;
Exit;
end;
end;
end;
MainForm.ThreadIsOk[FiBigBlockNO] := true;
 
目前是开了一个线程来测试的,也还是出现上述错误,问题是我用IdHTTP来发送,又不是新开一端口再次发送,为什么会运行一段时间后才报此错呢?谢谢大家了.
 
下面是摘自MSDN的一段关于10048错误代码的描述:
When bind is called with a wild-card address (involving ADDR_ANY), a WSAEADDRINUSE error could be delayed until the specific address
----------------------------------------------------------------
is &quot;committed.&quot;
--------------
This could happen with a call to other function later, including connect, listen, WSAConnect or WSAJoinLeaf.

划线的部分说明这种错误的产生会在上述情况下延迟。
 
发送的时候新建个idHTTPPost应该可以吧
 
发一次创建一次的话,太耗资源了吧.
 
晕,怎么再没人来了呢?
先顶起来再说吧.
 
先顶起来再说吧
 
后退
顶部