How is the correct way to Parse an IPAddress from String to System.Net.IPAddress on C# with Framework 4.6.
I am trying to implement with Visual Studio 2017 NuGet TCPSimple a TCP/IP Server and Client for testing purposes, but I got a System.FormatException "Input string was not in a correct format".
I have tried different approaches, but they're not working at all!
private void btnStart_Click(object sender, EventArgs e)
{
txtStatus.Text += "Server starting...";
//var address = System.Net.IPAddress.Parse("10.0.11.174").GetAddressBytes();
//long m_Address = ((address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]) & 0x0FFFFFFFF);
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(txtHost.Text));
//System.Net.IPAddress ip = new System.Net.IPAddress.Parse("127.0.0.1");
server.Start(ip,Convert.ToInt32(txtPort.Text));
}
There is an IPAddress.Parse method in the .NET framework to handle this.
IPAddress ip = IPAddress.Parse(txtHost.Text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With