UDP Socket Set Timeout

前端 未结 2 559
Happy的楠姐
Happy的楠姐 2020-12-01 01:57

I am trying to set a 100ms timeout on a UDP Socket. I am using C. I have posted relavent pieces of my code below. I am not sure why this is not timing out, but just hangs

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 02:38

    I have the same problem. I tried to adopt the solution you suggested, using the timeval struct. But it did not seem to work.

    I have read on the Microsoft documentation and the time should be a DWORD with the number of milliseconds, but there is also another thing to do, If the socket is created using the WSASocket function, then the dwFlags parameter must have the WSA_FLAG_OVERLAPPED attribute set for the timeout to function properly. Otherwise the timeout never takes effect.

提交回复
热议问题