c# why?,howto? Cannot implicitly convert type 'string' to 'System.Net.IPAddress'

private IPAddress localaddr = Dns.GetHostEntry(textBox1.Text).AddressList[0].ToString();//"127.0.0.1";


private IPAddress localaddr = "127.0.0.1";


myListener = new TcpListener(localaddr,port);


localaddr, i'm stuck here, for debugging.

// Cannot implicitly convert type 'string' to 'System.Net.IPAddress'
Natural_DemonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
philipjonathanConnect With a Mentor Commented:
localhost is always '127.0.0.1'
0
 
philipjonathanCommented:

private IPAddress localaddr = IPAddress.Parse("127.0.0.1");
myListener = new TcpListener(localaddr,port);

Open in new window

0
 
AUmidhCommented:
Try this

private IPAddress localaddr = IPAddress.Parse("127.0.0.1");
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
margajet24IT Business AnalystCommented:
IPAddress localaddr =  IPAddress.Parse("127.0.0.1");
0
 
Natural_DemonAuthor Commented:
thanks you for the promp rely,

IPAddress localaddr =  IPAddress.Parse("127.0.0.1"

how to get addres of localhost?
0
 
Rahul Goel ITILSenior Consultant - DeloitteCommented:

//For parsing the string to IP
IPAddress ip =  IPAddress.Parse("127.0.0.1")
 
// To get the localhost IP
IPHostEntry iphost = Dns.GetHostByName(Dns.GetHostName());
IPAddress[] addr = iphost.AddressList;
 
for (int i = 0; i < addr.Length; i++)
{
                listBox1.Items.Add(string.Format("IP Address {0}: {1} ", i, addr[i].ToString()));
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.