UWP client socket block when try to connect on Java server (release mode)

 ̄綄美尐妖づ 提交于 2019-12-24 01:04:44

问题


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:


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



来源:https://stackoverflow.com/questions/51985939/uwp-client-socket-block-when-try-to-connect-on-java-server-release-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!