1

我正在尝试查看计算机 localhost 上的端口 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

即使它被转发,它也会认为它不是。代码有什么问题?

4

1 回答 1

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
于 2012-11-22T15:48:07.490 回答