Search code examples
c#uwpwin-universal-appwifi-directwindows-10-iot-core

UWP WiFi-Direct disconnects after second incoming StreamSocketListener connection


Currently i'm about to figure out, what my Problem with WiFi direct in a UWP app on Windows 10 IoT Core is. The Goal is to let a StreamSocketListener accept incoming Connections from WiFi-direct. This works well for the first Connection i make, the second request to the StreamSocketListener destroys the WiFi-direct session and it disconnects. As a side note, i have to use the legacy WiFi-Direct implementation with SSID and Passphrase. Here is some sample Code

WiFi Direct publisher

WiFiDirectAdvertisementPublisher _publisher = new WiFiDirectAdvertisementPublisher();
_publisher.StatusChanged += OnStatusChanged;

WiFiDirectConnectionListener _listener = new WiFiDirectConnectionListener();

try
{
    _listener.ConnectionRequested += OnConnectionRequested;
}
catch
{
    return;
}

_publisher.Advertisement.ListenStateDiscoverability = WiFiDirectAdvertisementListenStateDiscoverability.Normal;

_publisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
_publisher.Advertisement.LegacySettings.IsEnabled = true;

PasswordCredential creds = new PasswordCredential();
creds.Password = passphrase;
_publisher.Advertisement.LegacySettings.Passphrase = creds;
_publisher.Advertisement.LegacySettings.Ssid = ssid;

_publisher.Start();

if (_publisher.Status == WiFiDirectAdvertisementPublisherStatus.Started)
{
    // OK
}
else
{
    // Error
}

OnConnectionRequested EventHandler

WiFiDirectConnectionRequest connectionRequest = connectionEventArgs.GetConnectionRequest();

WiFiDirectDevice wfdDevice = null;

try
{
    wfdDevice = await WiFiDirectDevice.FromIdAsync(connectionRequest.DeviceInformation.Id);
}
catch
{
    //
}

wfdDevice.ConnectionStatusChanged += OnConnectionStatusChanged;

listEndpointPairs = wfdDevice.GetConnectionEndpointPairs();

StreamSocketListener

_listener = new StreamSocketListener();
await _listener.BindEndpointAsync(listEndpointPairs[0].LocalHostName, "80");
listener.ConnectionReceived += (sender, args) => ConnectionReceivedHandler(args);

As i said before, it works well, but i can not send a second request to the StreamSocketListener, if i do, the WiFi-direct Connection gets disconnected. Do i miss something or made a fault?

Thanks in advice


Solution

  • I think this is solved, because MS write says in the changelog for build 17110 (current beta) the following under known issues

    The IoTCore device has to be the connecting device – it will not work as the advertising device with another device initiating the connection.
    

    So it seems that there is currently no way to do that.