zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    MySQL主从复制搭建
    CSS基本样式简单介绍
    前端代码编码规范
    Markdown语法简单介绍
    Java API 操作Redis
    Java API 操作Zookeeper
    MySQL优化
    ES 可视化工具
    消息队列MQ
    Docker基础
  • 原文地址:https://www.cnblogs.com/LCX/p/1708527.html
Copyright © 2011-2022 走看看