We help IT Professionals succeed at work.

DNS Networking

NewMom2Brandon
on
317 Views
Last Modified: 2010-04-15
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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);
            }
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Did you try looking up the host name IP address using DNS?

Bob

Author

Commented:
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"
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Can you show me what you tried?

Bob

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
If that works, you should go with that.

Bob

Author

Commented:
Got it. Thank you
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.