4

I know this should be obvious, but I have found far too many DIFFERENT answers and the ones I've tried all fail (sometimes or all the time), so...

We are working on a service and some applications that run at startup on a Windows 10 computer that performs an automatic login. The service and applications require Windows sockets for TCP, UDP and Multicast. Most of the time, our programs fail because they get errors about the network not being ready and such. Currently, we work around this by just adding a dumb, fixed length delay time before attempting to start, but we would prefer to start as soon at the network is ready to be used.

Our most recent attempt was to wait on the LanmanWorkstation (Workstation) service, but that generally reports it is running/ready before the sockets functions will succeed. I have also seen suggestions to use LanmanServer (Server) or Netman (Network Connections) or maybe even Tcpip (TCP/IP Protocol Driver), but I cannot find anything definitive. One would think this is a common requirement, so why would Microsoft make the info so difficult to find?

Ahem. Does any know a definitive method for a service or application to wait until winsock functions will succeed before using them? Short of a spin wait on a failing winsock function, of course!

Steve Valliere
  • 1,119
  • 7
  • 12
  • 2
    https://stackoverflow.com/a/4623409/3975177 maybe? – Swordfish Oct 17 '18 at 18:55
  • That might work. It doesn't specifically say that the initial setting of an address is a change and my assumptions about Microsoft doing the logical thing just about always get me in trouble! (smile) Thanks, though, I'll see about getting something set up to test it. – Steve Valliere Oct 17 '18 at 19:02
  • may be you need [Network Awareness](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mpc/network-awareness) – RbMm Oct 18 '18 at 00:39
  • "Network Awareness" sound good, but after reading about it, I don't think it is what I need. I didn't mention this before, but our networks are completely isolated from the internet and are often "island" networks with NO external connectivity. We're trying to determine when it is OK to start using winsock functionality in order to communicate within our local, private, isolated subnet only. – Steve Valliere Oct 18 '18 at 12:36
  • i think you need `CoCreateInstance` for `NetworkListManager` and register your implementation of `INetworkListManagerEvents`. when any change will be in network status you got `ConnectivityChanged` call with [`NLM_CONNECTIVITY`](https://learn.microsoft.com/en-us/windows/desktop/api/netlistmgr/ne-netlistmgr-nlm_connectivity). i be how minimum try this for see result of calls. implementation for this (vista+) simply enough – RbMm Oct 21 '18 at 21:12
  • also may be will be interesting this - [network_change_notifier_win.cc](https://chromium.googlesource.com/chromium/src/net/+/master/base/network_change_notifier_win.cc) – RbMm Oct 21 '18 at 21:24
  • @Swordfish: I built Microsoft's example from the link and tried it in the startup group on a machine with auto-logon enabled and it doesn't work. Apparently, just becoming available is NOT a _change_ to the network address table. – Steve Valliere Oct 22 '18 at 13:31
  • also @Swordfish: (I forgot to consider that the function might also fail if the network is already available. Either way, it didn't work for me. – Steve Valliere Oct 22 '18 at 13:40

0 Answers0