为什么我总是在这段代码中得到 WSAETIMEDOUT 错误:
var fUDPBuf: array [1..UdpPacketSize] of byte;
{...}
UDPSocket := TUDPBlockSocket.Create;
UDPSocket.Bind(UDPIP, UDPPort);
if UDPSocket.LastError = 0 then
Raise EDevFail.Create(Format(SPortFailed, [UDPPort]));
while not Terminated do begin
BytesRead := UDPSocket.RecvBufferEx(@fUDPBuf[1], UdpPacketSize, 1000);
if BytesRead <= 0 then
case UDPSocket.LastError of
0, WSAETIMEDOUT: Continue;
WSAECONNRESET, WSAENETRESET,
WSAENOTCONN, WSAECONNABORTED,
WSAENETDOWN: begin
Raise EDevFail.Create(UDPSocket.GetErrorDesc(UDPSocket.LastError));
UDPSocket.CloseSocket;
end;
else begin
Raise EDevFail.Create(UDPSocket.GetErrorDesc(UDPSocket.LastError));
UDPSocket.CloseSocket;
end;
end;
//Sleep(1);
ProcessData(@fUDPBuf[1]);
inc(PacketCount);
end;
我确信我从 e 网络设备接收的 UDP 数据与 UdpPacketSize 一样多。