socket.connect errors

Posted on 2006-04-05
Last Modified: 2010-04-16
I have the following piece of code:

                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                ep = new IPEndPoint(Dns.GetHostEntry(ipAddress).AddressList[0], port);
            catch (Exception ex)
                // doubtfull....
                if (socket != null && socket.Connected)
                throw new FtpException("Can't connect to remote server", ex.Message);

When my conenction to the internet is busy, such as when downloading, the code above throws the exception.  Is there anything I can do to remedy this?  try again?  different port?  I don't know that much about sockets, so I'm at a loss here.
Question by:rmmarsh
    LVL 6

    Assisted Solution

    What kind of Exception are you getting, what is it saying and who is throwing it?
    Both Dns.GetHostEntry and socket.Connect can throw exceptions so you have to take a look at the exception you are catching
    LVL 4

    Accepted Solution

    What is the exception message you get?
    There are several exceptions that could be thrown when calling Connect, so the exception type and message would be helpful.

    Author Comment

    Don't know... will have to test it and get back to you... sorry...

    Author Comment

    The problem appears to have gone away... hmmmm

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now