I made a server with localhost(127.0.0.1) in C using a winSocket sample given on Microsoft website. It is simple C console app. Then I made a client in a UWP app with C# with using System.Net.Sockets class as per the Microsoft doc. The client did not connect.
I checked again by making the client in C console app, python code, simple C# console app and It was successfully connected and working in all but when I make it in UWP app it is not working. I checked with all possible changes like checking host file in drivers folder, changing "localhost" to "127.0.0.1", firewall off, required dotnet components etc.
One thing more, the client in UWP app is successfully connected only when we are debugging the client code. But when we make final setup/installation in release it is not working. This is very strange !!
The error it is showing like below-
SocketException : {0}System.Net.Internals.SocketExceptionFactory ExtendedSocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 127.0.0.1:27311 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at SmartCabinetSolution.App.RFIDSocket.Start()
CodePudding user response:
One thing more, the client in UWP app is successfully connected only when we are debugging the client code.
It looks network loopback cause this problem (allow local network loopback is by default in debug model) , if you want to create a TCP/IP connection between two processes running on the same device and one of them is a UWP app you must enable localhost loopback. For more detail please refer Add loopback exemption for App Installer.