I am taking a class right now where some of the examples are in C #. Since my laptop is running Linux, I use Mono 2.6.7 on Ubuntu.
I am trying to compile the following code:
using System.Net.Sockets;
using System.Net;
using System;
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();
}
}
When I compile the code, I get:
/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
I am a beginner in C #; This is the first C # program I've ever compiled. I tried a google search, but I didn’t have a lot of hits for this problem. Is this a problem with Mono?
source
share