• System.Net.Sockets中,无法定义连接超时时间


      Sub Main(ByVal args As String())
            Dim strTxt As String = ""
            Dim PathName As String = args(0)
            Dim sReader As StreamReader
            sReader = New StreamReader(PathName, Encoding.Default)
            Dim S As String
            S = sReader.ReadLine()
            While Not S Is Nothing
                If UrlExist(S.ToString) = True Then
                    Console.WriteLine(S.ToString & "|" & "True")
                Else
                    Console.WriteLine(S.ToString & "|" & "False")
                End If
                S = sReader.ReadLine()
            End While
            sReader.Close()
        End Sub
    
    
        Public Function UrlExist(ByVal sURL As String) As Boolean
            Dim temp As Boolean = False
            Try
                ' Dim ip As IPAddress = IPAddress.Parse("218.5.78.118")
                Dim ip As String = Dns.GetHostByName(sURL).AddressList(0).ToString()
                Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                'sock.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Error, 5000) 没效果
                'sock.SetSocketOption(SocketOptionLevel.Tcp,SocketOptionName.SendTimeout,5000) 
                sock.Connect(ip, 80)
                sock.Close()
                temp = True
            Catch e As SocketException
                temp = False
            End Try
    
            Return temp
        End Function
    
  • 相关阅读:
    eval()
    promise
    console.log()和console.dir()、console.table()的区别
    SSM框架搭建+easyui增删改查
    虚成员
    关键字 explicit
    复制控制
    变量、静态变量
    关键字 extern
    关键字 static
  • 原文地址:https://www.cnblogs.com/LCX/p/1708527.html
Copyright © 2020-2023  润新知