• Welcome to Valhalla Legends Archive.
 

Determining If Resolve is Needed?

Started by BaDDBLooD, January 22, 2005, 07:17 PM

Previous topic - Next topic

BaDDBLooD



   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



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
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

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.

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.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

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

l)ragon

    Private Function ResolveIP(ByVal strServer As String) As IPAddress
        Return Dns.Resolve(strServer).AddressList(0)
    End Function
Perhaps you'll like the shorter way of doing this.
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

dxoigmn

Why not just call Connect and let it handle the resolving?


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


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

MyndFyre

Quote from: dxoigmn on January 23, 2005, 01:05 AM
Why not just call Connect and let it handle the resolving?


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


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

I don't see those overloads.  The only method I see for Socket::BeginConnect is:

[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
);

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

dxoigmn

Quote from: MyndFyre on January 23, 2005, 02:04 AM
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.

I am using .NET 2.0.

BaDDBLooD

Quote from: MyndFyre on January 23, 2005, 02:04 AM
Quote from: dxoigmn on January 23, 2005, 01:05 AM
Why not just call Connect and let it handle the resolving?


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


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

I don't see those overloads.  The only method I see for Socket::BeginConnect is:

[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
);

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.

What, exactly, do you mean by statements number one and two.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.