3

I've got a problem with my soft ap solution. When i connect a client to the ap the connection gets established and everything works fine. But I've noticed that when i set a ping to the host, it looses connection every 2 minutes and then suddenly regains connection. This unfortunatly is unnacceptable for my solution.

I found this link: On using the WiFi Direct Api on Windows? , which describes the same problem, but the answer isn't clear enough and i would like a code example or a more elaborate explanation.

In my solution, I use this class: https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifidirect.wifidirectadvertisementpublisher?view=winrt-19041 with legacy settings set to "enabled": https://learn.microsoft.com/en-us/uwp/api/windows.devices.wifidirect.wifidirectlegacysettings.isenabled?view=winrt-19041

On using the WiFi Direct Api on Windows?

Ryan
  • 31
  • 1
  • Is your machine powering down? Usually you set the KeepAive option which periodicaly sends a empty message to server so the server doesn't close the connection. See following : https://learn.microsoft.com/en-us/uwp/api/Windows.Networking.Sockets?view=winrt-19041#using-datagramsocket-with-wi-fi-direct – jdweng Nov 25 '20 at 17:22
  • Hi, thanks for your answer. I don't use the KeepAlive option. In my solution I only use the WiFiDirectAdvertisementPublisher class linked in my question. Do I need to implement code from Windows.Networking.Sockets? I noticed that here: https://learn.microsoft.com/en-us/uwp/api/windows.networking.sockets.controlchanneltrigger.serverkeepaliveintervalinminutes?view=winrt-19041 you could only set the minimum time to 15 minutes, but with that the connection from device to accesspoint would have been interrupted 7 times already. – Ryan Nov 25 '20 at 17:49
  • 1
    The WifiDriect already uses sockets. The issue is how to set the option. I'm not sure if the issue right now is due to a power saving option being set so the connection closes when going into power saving mode; or a KeepAlive. The link you found is the server end of a KeepAlive and not your client. The KeepAlive is suppose to prevent the server from closing the connection when no data is sent. So normally a server wait 15 minutes before closing (but this time can be shorter). The client to prevent the server from closing will send empty messages so the server doesn't see an idle channel – jdweng Nov 25 '20 at 18:01
  • Maybe a stupid question but shouldn't me pinging from both ends prevent the socket from going into power saving? Also the script I wrote is server side, the client just connects using the normal windows wifi interface to connect via ssid and psk. So i only have the abbility to change windows settings on the client where as i can also edit the script on the server. Maybe also important to point out is, that the client doesnt gain internet access through the server, the ap is merely for a connection between client and server. – Ryan Nov 25 '20 at 18:13
  • I don't design these machines!!!! You have to check the machine power down options especially laptops. The manufacturer's want to advertise battery life and they will do anything to get more life. Suppose you had a PC connected to a website that constantly was updating. Do you want machine to go into low power mode when you walk away and stop using mouse and keyboard even though the internet connection is still pinging? – jdweng Nov 25 '20 at 18:26
  • Hi @Ryan , I also did an UWP application and i get the OnConnectionRequested that is triggered every two minutes. It seems that i have the same problem and it has a major impact on applications using the network. Have you found a workaround or a parameter that prevents this from happening ? – L2M Mar 04 '22 at 14:04

1 Answers1

0

I have encountered exactly the same problem because I removed the following line from MS sample :

var wiFiDirectDevice = await WiFiDirectDevice.FromIdAsync(deviceInfo.Id);

It seems that if you don t create the wifiDirectDevice object, Windows will automatically disconnect the client two minutes later (although in the meantime you have been able to exchange some data). What helped me was to compare my code with the following sample : https://github.com/gerfen/WiFiDirectLegacyAPCSharp/blob/master/WiFiDirectHotspotManager.cs#L128

Note that I also encountered another problem when I added this line because an exception is triggered depending on the client device configuration ( see the following topic : Wi-Fi Direct UWP timeouts (Exception from HRESULT: 0x800705B4))

L2M
  • 51
  • 4