Reputation: 11
During development, we usually use localhost as the hostname, like the following
Dim serverListener As New TcpClient("localhost", 8585)
I want the user to be able to enter their IP address via a TextBox instead, like
Dim serverListener As New TcpClient(textbox1.text, 8585)
However, this is not working for me. Any ideas? Thanks!
Upvotes: 0
Views: 502
Reputation: 5427
The form of the TcpClient
constructor that accepts a string
and an int
parameter expects a hostname and a port, not an IP address.
You might want to use the TcpClient
constructor that takes an IPEndPoint
parameter instread. There is more information on the IPEndPoint
class on MSDN, but in short it represents an IP address and a port number.
Upvotes: 1
Reputation: 6275
Perhaps this will help?
You can also use IPAdress.TryParse() to check if its a valid adress
Upvotes: 1