socket.connect errors

I have the following piece of code:

            try
            {
                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                ep = new IPEndPoint(Dns.GetHostEntry(ipAddress).AddressList[0], port);
                socket.Connect(ep);
            }
            catch (Exception ex)
            {
                // doubtfull....
                if (socket != null && socket.Connected)
                    socket.Close();
                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.
rmmarshAsked:
Who is Participating?
 
alaranCommented:
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.
0
 
e1vCommented:
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
0
 
rmmarshAuthor Commented:
Don't know... will have to test it and get back to you... sorry...
0
 
rmmarshAuthor Commented:
The problem appears to have gone away... hmmmm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.