Can't establish Tcp StreamSocket connection between WiFiDirectServices

Viewed 35

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:

  1. StreamSocketListener is created
  2. BindEndpointAsync() with a specific port number (or BindServiceNameAsync() with empty string) is called, and it is successful
  3. WiFiDirectServiceSession.AddStreamSocketListenerAsync is called

On computer B:

  1. WiFiDirectServiceSession's RemotePortAdded event is triggered. In RemotePortAdded handler,

  2. New StreamSocket is created

  3. 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?

0 Answers
Related