【问题标题】:Reason of mono-io-layer-error (10013)单 io 层错误 (10013) 的原因
【发布时间】:2017-09-27 10:15:43
【问题描述】:

我正在使用 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)
        {

        }
    }

【问题讨论】:

    标签: c# android xamarin xamarin.android mono


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-10-10
      • 2014-07-23
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 2017-05-22
      • 2016-02-26
      • 2015-08-07
      • 1970-01-01
      相关资源
      最近更新 更多