繁体   English   中英

单层io层错误的原因(10013)

[英]Reason of mono-io-layer-error (10013)

我正在使用XAMARIN为我的android应用程序创建一个聊天应用程序,但是当我要启动tcp侦听器时,我会遇到mono-io-layer-error(10013)。 Internet选项已被选择为允许。

我在主要Activity的OnCreate()方法内部调用此方法。

我的代码是这样的:

private void CreateListener()
    {
        HttpListener listener = null;
        HttpListenerContext context = null;
        HttpListenerRequest request = null;
        HttpListenerResponse response = null;
        string PortNumber = "8080";
        string requestUrl;
        Boolean listen = false;

        try
        {
            if (listener == null)
            {
                listener = new HttpListener();
                listener.Prefixes.Add("http://192.168.20.93" + PortNumber + "/");
                listener.Start();
                listen = true;
                while (listen)
                {
                    try
                    {
                        context = listener.GetContext();
                    }
                    catch (Exception e)
                    {
                        listen = false;
                    }
                    if (listen)
                    {
                        request = context.Request;
                        requestUrl = request.Url.ToString();

                        // Process request and/or request Url
                    }
                }
            }
        }
        catch (Exception ex)
        {

        }
    }

问题是您添加到Prefixes字符串是错误的。

URI前缀字符串由方案(http或https),主机,可选端口和可选路径组成,例如: http://www.contoso.com:8080/customerData/ : http://www.contoso.com:8080/customerData/ : http://www.contoso.com:8080/customerData/

尝试更改您的代码listener.Prefixes.Add("http://192.168.20.93" + PortNumber + "/"); listener.Prefixes.Add("http://192.168.20.93:" + PortNumber + "/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM