Link to home
Start Free TrialLog in
Avatar of NewMom2Brandon
NewMom2Brandon

asked on

DNS Networking

I currently have a Server and Client application written.

The client ues TCP/IP Sockets to connect through to the server via its IP addresses.

I recently ran into a situation that would require a change in this functionality. I need to use DNS name instead.

Does anyone have any code examples or links that can help me on this
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NewMom2Brandon
NewMom2Brandon

ASKER

This is what I have right now

            try
            {
                //create a new client socket ...
                m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,   ProtocolType.Tcp);

                System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(IPADDY HERE);
                System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, PortNoHERE);

                m_socClient.Connect(remoteEndPoint);
            }
            catch (SocketException se)
            {
                System.Diagnostics.EventLog.WriteEntry(this.ToString(),
                  "ERROR DURING CONNECT" + se.ErrorCode + ":: " + se.Message);
            }
Did you try looking up the host name IP address using DNS?

Bob
I tried to put in what you listed above.

So far I see a error "A field initializer cannot reference the nonstatic field, method or property"
Can you show me what you tried?

Bob
I just tried again and was able to get a IP address

                IPHostEntry hostInfo = Dns.GetHostEntry("PCNAME HERE");
                // Get the IP address list that resolves to the host names contained in the
                // Alias property.
                IPAddress[] address = hostInfo.AddressList;
                // Get the alias names of the addresses in the IP address list.
                String[] alias = hostInfo.Aliases;

So do I just keep what I already have in place then above. Or is there another way
If that works, you should go with that.

Bob
Got it. Thank you