VB Code:
Public Class SocketMaster Public Event OnConnect() Public Event OnDisconnect() Public Event OnError(ByVal Err As SocketException) Private Socket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Public Sub Connect(ByVal server As String, ByVal port As Integer) Dim hostEntry As IPHostEntry = Nothing Dim address As IPAddress Try hostEntry = Dns.Resolve(server) For Each address In hostEntry.AddressList Dim endPoint As New IPEndPoint(address, port) Socket = New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) Try Socket.Connect(endPoint) If Socket.Connected = True Then RaiseEvent OnConnect() Exit For End If Catch Err As SocketException RaiseEvent OnError(Err) End Try Next address Catch Err As SocketException RaiseEvent OnError(Err) End Try End Sub Public Sub Disconnect() Try Socket.Close() RaiseEvent OnDisconnect() Catch Err As SocketException RaiseEvent OnError(Err) End Try End Sub 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.




Reply With Quote