I am running the Wi-Fi Direct services sample on my two Win11 laptops.
Using the default ConfigMethod, the WiFiDirectServiceSession can be created. At the step of creating socket connection, I was able to create UDP DatagramSocket and send data. But I could not create the TCP StreamSocket connection.
Here is the flow after WiFiDirectServiceSession is created.
On computer A:
- StreamSocketListener is created
- BindEndpointAsync() with a specific port number (or BindServiceNameAsync() with empty string) is called, and it is successful
- WiFiDirectServiceSession.AddStreamSocketListenerAsync is called
On computer B:
WiFiDirectServiceSession's RemotePortAdded event is triggered. In RemotePortAdded handler,
New StreamSocket is created
Call StreamSocket's ConnectAsync method with either "EndpointPair" or just the "remoteHostName & remoteServiceName". This method returns error "An attempt was made to access a socket in a way forbidden by its access permissions."
The sample UWP is already listed as an allowed App in Firewall settings. I have also tried to turn off Firewalls, and the tips from this blog. But I still can't get rid of this error.
Has anyone been able to establish the Tcp connection between WiFiDirectServices?