Synapse 库中的 WSAETIMEDOUT 消息
为什么我总是在这段代码中收到 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;
我确信我从网络设备接收到的 UDP 数据与 UdpPacketSize 一样多。
Why I always get WSAETIMEDOUT error in this code :
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;
I'm sure that I receive UDP data from e network device as much as UdpPacketSize.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在调用“UDPSocket.RecvBufferEx(@fUDPBuf[1], UdpPacketSize, 1000);” 我认为最后一个数字是超时时间。 这样做是为了让它不会永远等待,而是定期检查线程是否已使用 while 循环条件终止。 所以对于此类代码来说,超时是正常情况,可以忽略。
In the call "UDPSocket.RecvBufferEx(@fUDPBuf[1], UdpPacketSize, 1000);" I would presume that the last number is the timeout period. This is done so that it doesn't sit waiting forever, but rather checks periodically if the thread has been Terminated using the while loop condition. So the timeout is a normal situation for this sort of code, and can be ignored.
我解决了我的问题:)
必须是
并且
必须是
用于检查数据来自的 IP 地址
I solved my problem :)
must be
And
must be
For to check IP address where data come from
我找到。 LastError中的错误
为 10049=此时无法分配请求的地址。 那么为什么我无法绑定UDPIP地址。 我检查了IP和端口。 这些都是正确的。 并且没有其他软件监听这个端口。
I found that. The error is in
LastError is 10049=Can't assign requested address at this point. So why I couldn't Bind the UDPIP address. I've check the IP and Port. These are correct. And there is no other software listening this port.