我试图查看本地主机(计算机)上的端口57875是否已关闭。 这是我到目前为止的代码:
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
即使转发,它也会认为不是。代码有什么问题?
答案 0 :(得分:1)
这里有一个例子:
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