Valhalla Legends Forums Archive | .NET Platform | Determining If Resolve is Needed?

AuthorMessageTime
BaDDBLooD
[code]

  Public Sub Connect(ByVal Server As String, ByVal Port As Integer)
        Try
            Dim ipHostInfo As IPHostEntry = Dns.Resolve(Server)
            Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
            Dim Destination As New IPEndPoint(ipAddress, Port)
            Socket.BeginConnect(Destination, AddressOf Socket_Connected, Socket)
        Catch Ex As SocketException
            RaiseEvent OnError(Ex.Message)
            Socket.Close()
        End Try
    End Sub

[/code]

How do you tell if you need to resolve the host, or not.

Eeverytime this procedure is called, my project stops, while it is resolving the host.  I only want it to resolve address's like www.google.com, and not 127.56.191.8

Thanks Alot
January 23, 2005, 1:17 AM
UserLoser.
For DNS lookups, you should create a thread which handles it so it doesn't cause your application to freeze.  This freezing is probably caused by it waiting for a response from whatever DNS server which is all done from the main thread.
January 23, 2005, 5:20 AM
BaDDBLooD
Yeah ok, i can do that.  I still have the problem of Resoving both a Dotted Quad address or whatever ( 255.255.255.255 ) and a Domain name like google.com.  I only want to resolve domain names.
January 23, 2005, 5:29 AM
UserLoser.
Not sure how to go about this in that stuff Microsoft calls .NET, but otherwise you'd be able to use getaddrinfo, getnameinfo, gethostbyname, gethostbyaddr
January 23, 2005, 5:56 AM
dRAgoN
[code]    Private Function ResolveIP(ByVal strServer As String) As IPAddress
        Return Dns.Resolve(strServer).AddressList(0)
    End Function[/code]Perhaps you'll like the shorter way of doing this.
January 23, 2005, 6:53 AM
kamakazie
Why not just call Connect and let it handle the resolving?

[code]
public void Connect(string host, int port)
public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback requestCallback, object state)
[/code]

Note that is probably better that you use the latter so Connect doesn't block but rather fires a callback.
January 23, 2005, 7:05 AM
Myndfyr
[quote author=dxoigmn link=topic=10271.msg96279#msg96279 date=1106463913]
Why not just call Connect and let it handle the resolving?

[code]
public void Connect(string host, int port)
public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback requestCallback, object state)
[/code]

Note that is probably better that you use the latter so Connect doesn't block but rather fires a callback.
[/quote]

I don't see those overloads.  The only method I see for Socket::BeginConnect is:
[code]
[Visual Basic]
Public Function BeginConnect( _
  ByVal remoteEP As EndPoint, _
  ByVal callback As AsyncCallback, _
  ByVal state As Object _
) As IAsyncResult

[C#]
public IAsyncResult BeginConnect(
  EndPoint remoteEP,
  AsyncCallback callback,
  object state
);
[/code]
My local installation of the MSDN Library is October 2004; this is .NET 1.1.

For the question -- if it's in dotted-quad notation, IMHO you should still use DNS.Resolve.  It gives you a few perks --
1.) You don't need to try to connect; if DNS doesn't resolve the IP, then you can't connect anyway.
2.) You don't need to try and convert the dotted-quad string into a byte array to create a new IPAddress object.
January 23, 2005, 8:04 AM
kamakazie
[quote author=MyndFyre link=topic=10271.msg96282#msg96282 date=1106467496]
I don't see those overloads.  The only method I see for Socket::BeginConnect is:

My local installation of the MSDN Library is October 2004; this is .NET 1.1.
[/quote]

I am using .NET 2.0.
January 23, 2005, 9:09 AM
BaDDBLooD
[quote author=MyndFyre link=topic=10271.msg96282#msg96282 date=1106467496]
[quote author=dxoigmn link=topic=10271.msg96279#msg96279 date=1106463913]
Why not just call Connect and let it handle the resolving?

[code]
public void Connect(string host, int port)
public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback requestCallback, object state)
[/code]

Note that is probably better that you use the latter so Connect doesn't block but rather fires a callback.
[/quote]

I don't see those overloads.  The only method I see for Socket::BeginConnect is:
[code]
[Visual Basic]
Public Function BeginConnect( _
   ByVal remoteEP As EndPoint, _
   ByVal callback As AsyncCallback, _
   ByVal state As Object _
) As IAsyncResult

[C#]
public IAsyncResult BeginConnect(
   EndPoint remoteEP,
   AsyncCallback callback,
   object state
);
[/code]
My local installation of the MSDN Library is October 2004; this is .NET 1.1.

For the question -- if it's in dotted-quad notation, IMHO you should still use DNS.Resolve.  It gives you a few perks --
1.) You don't need to try to connect; if DNS doesn't resolve the IP, then you can't connect anyway.
2.) You don't need to try and convert the dotted-quad string into a byte array to create a new IPAddress object.
[/quote]

What, exactly, do you mean by statements number one and two.
January 25, 2005, 10:19 PM

Search