加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Mono说’System.Net.Dns.GetHostEntry(string)’由于其保

发布时间:2020-12-15 23:56:09 所属栏目:百科 来源:网络整理
导读:我正在上课,其中一些例子在C#中.由于我的笔记本电脑运行 Linux,我在Ubuntu上使用Mono 2.6.7. 我正在尝试编译以下代码: using System.Net.Sockets;using System.Net;using System;/// summary/// Example program showing simple TCP socket connections in
我正在上课,其中一些例子在C#中.由于我的笔记本电脑运行 Linux,我在Ubuntu上使用Mono 2.6.7.

我正在尝试编译以下代码:

using System.Net.Sockets;
using System.Net;
using System;

/// <summary>
/// Example program showing simple TCP socket connections in C#.NET.
/// Rather than reading and writing byte arrays,this example show
/// how to use a stream reader in the client.
/// TCPSocketServer is the socket server.
/// <author>Tim Lindquist ASU Polytechnic Department of Engineering</author>
/// <version>September,2009</version>
/// </summary>
public class TCPSocketServer {

  public static void Main (string [] args) {
    IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
    TcpListener tcpl = new TcpListener(ipAddress,9090);
    tcpl.Start();
    Console.WriteLine("TCPSocketServer waiting for connections on 9090");
    Socket sock = tcpl.AcceptSocket();
    string msg = "Hello Client";
    Byte[] msgBytes = System.Text.Encoding.ASCII.GetBytes(msg);
    sock.Send(msgBytes,msgBytes.Length,SocketFlags.DontRoute);
    Console.WriteLine("Message-Hello Client-sent to client.");
    tcpl.Stop();
    sock.Close();
  }
}

当我编译代码时,我得到:

/home/vivin/Projects/cst420/CSSockets/src/TCPSocketServer.cs(16,31): error CS0122: `System.Net.Dns.GetHostEntry(string)' is inaccessible due to its protection level
/usr/lib/mono/gac/System/1.0.5000.0__b77a5c561934e089/System.dll (Location of the symbol related to previous error)
ompilation failed: 1 error(s),0 warnings

我是C#新手;这是我编写的第一个C#程序.我尝试在谷歌上搜索,但我没有得到很多关于这个问题的点击.这是Mono的问题吗?

解决方法

System.Net.Dns.GetHostEntry是在.NET Framework 2.0中引入的.在Mono的实现中,它也出现在2.0之前的版本中,但标记为内部而非公共.您似乎正在编译.NET Framework 1.0.

/mcs/class/System/System.Net/Dns.cs开始:

#if NET_2_0
    public
#else
    internal
#endif
    static IPHostEntry GetHostEntry (string hostNameOrAddress)
    {
        // ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读