UWP client socket block when try to connect on Jav

2019-07-09 11:49发布

I have a UWP StreamSocket client writted in C # on Windows and I have a Java server socket listening on port 8080.

In Visual Studio, in debug mode, all work very well, my server received good data. But, in release mode, the app is unable to connect to a socket.

I have added modes : internetClient, internetClientServer and privateNetworkClientServer into Package.appxmanifest file but there are no improvements.

Here is my code to connect to a socket host = 127.0.0.1 and port = 8080 for the test

public async Task ConnectSocket(string host, string port)
{
    try
    {
        socket = new StreamSocket();
        socket.Control.KeepAlive = true;
        HostName hostName = new HostName(host);
        await socket.ConnectAsync(hostName, port);
    }
    catch (Exception ex)
    {
        //....
    }
}

What is the problem and how can I repair this ?

1条回答
甜甜的少女心
2楼-- · 2019-07-09 12:34

You need to enable loopback for your UWP application. When you run in VS, it does it for you. When you run without VS, you need to do it yourself.

https://docs.microsoft.com/en-us/windows/iot-core/develop-your-app/loopback

查看更多
登录 后发表回答