• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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.
0
rmmarsh
Asked:
rmmarsh
  • 2
2 Solutions
 
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
 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now