VB Code:
  1. Public Class SocketMaster
  2.  
  3.     Public Event OnConnect()
  4.     Public Event OnDisconnect()
  5.     Public Event OnError(ByVal Err As SocketException)
  6.  
  7.     Private Socket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  8.  
  9.     Public Sub Connect(ByVal server As String, ByVal port As Integer)
  10.         Dim hostEntry As IPHostEntry = Nothing
  11.         Dim address As IPAddress
  12.         Try
  13.             hostEntry = Dns.Resolve(server)
  14.             For Each address In hostEntry.AddressList
  15.                 Dim endPoint As New IPEndPoint(address, port)
  16.                 Socket = New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
  17.                 Try
  18.                     Socket.Connect(endPoint)
  19.                     If Socket.Connected = True Then
  20.                         RaiseEvent OnConnect()
  21.                         Exit For
  22.                     End If
  23.                 Catch Err As SocketException
  24.                     RaiseEvent OnError(Err)
  25.                 End Try
  26.             Next address
  27.         Catch Err As SocketException
  28.             RaiseEvent OnError(Err)
  29.         End Try
  30.     End Sub
  31.  
  32.     Public Sub Disconnect()
  33.         Try
  34.             Socket.Close()
  35.             RaiseEvent OnDisconnect()
  36.         Catch Err As SocketException
  37.             RaiseEvent OnError(Err)
  38.         End Try
  39.     End Sub
  40.  
  41. End Class

This is my socket class

When you DNS like www.google.com and it gives you a list of address's, i want to ping each one to find the fastest, however i am unsure of how to do this.