0

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?

2
  • I'm not sure but the most possible reason for this should be that the socket has been held by some process. Have you tried to reset the socket by restarting the app or restarting computer A and then test again? Commented Sep 13, 2022 at 7:37
  • I don't think that is the case. The StreamSocketListener is created successfully (with a specific port or system selected port on Computer A) e.g. 'port123'. The error occurs when the remote computer B tries to connect to Computer A's port123. Commented Sep 16, 2022 at 17:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.