A
A
Alexander Kovalevich2016-04-19 15:43:21
.NET
Alexander Kovalevich, 2016-04-19 15:43:21

How to convert "System.String" to type "System.Net.IPAddress"?

Could not cast object type 'System.String' to type 'System.Net.IPAddress'.
Dim ServerIP = "127.0.0.1"
Dim ServerPort As Integer = 50000
TextBoxServerIP.Text = ServerIP
TextBoxServerPort.Text = ServerPort
Dim Server As New TcpListener(ServerIP, ServerPort)
Server.Start()
Where is the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2016-04-19
@DeusEx_Machine

As I understand it, you need to dance towards Parse

Dim ServerIP = "127.0.0.1"
Dim  address As IPAddress = IPAddress.Parse(ServerIP)
Dim ServerPort As Integer = 50000
TextBoxServerIP.Text = ServerIP
TextBoxServerPort.Text = ServerPort
Dim Server As New TcpListener(address, ServerPort)
Server.Start()

M
Maa-Kut, 2016-04-19
@Maa-Kut

Use IPAddress.Parse: https://msdn.microsoft.com/en-us/library/system.ne...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question