Reputation: 31
I am trying to see if port 57875 on localhost, the computer, is closed. Here is the code I have so far:
Try
Dim checkPort As TcpClient = New TcpClient("localhost", 57875)
Catch ex As Exception
MsgBox("WARNING: Port 57875 is not forwarded ! The game will probably encounter an error !")
End Try
Even if it is forwarded, it will think it isn't. What is wrong with the code?
Upvotes: 1
Views: 674
Reputation: 11063
Here you have an example:
Dim host As String = "localhost"
Dim port As Integer = 57875
Dim addr As IPAddress = DirectCast(Dns.GetHostAddresses(host)(0), IPAddress)
Try
Dim tcpList As New TcpListener(addr, port)
tcpList.Start()
Catch sx As SocketException
'Catch exception - No available port
End Try
Upvotes: 1