尝试在 Java 服务器上连接时 UWP 客户端套接字块(发布模式) [英] UWP client socket block when try to connect on Java server (release mode)

查看:54
本文介绍了尝试在 Java 服务器上连接时 UWP 客户端套接字块(发布模式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上有一个用 C# 编写的 UWP StreamSocket 客户端,并且我有一个 Java 服务器套接字侦听端口 8080.

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

在 Visual Studio 中,在调试模式下,一切正常,我的服务器收到了良好的数据.但是,在发布模式下,应用程序无法连接到套接字.

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.

我添加了模式:internetClientinternetClientServerprivateNetworkClientServerPackage.appxmanifest 文件,但没有改进.

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

这是我连接到套接字的代码 host = 127.0.0.1 和 port = 8080 用于测试

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 ?

推荐答案

您需要为 UWP 应用程序启用环回.当您在 VS 中运行时,它会为您完成.不用VS运行时,需要自己动手.

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

这篇关于尝试在 Java 服务器上连接时 UWP 客户端套接字块(发布模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆