Sign in to follow this  

[C#] Localhost refuses connection even when port is open

This topic is 3044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks, I am trying to send some information via a loopback network connection but I am getting the following error: No connection could be made because the target machine actively refused it The port is open on my firewall so I can't understand why this is happening. Also, in the hostEntry.AddressList there are 2 address the fist is ::1 and the second is the localhost. I take it the ::1 is the IPv6 version of localhost then? The socket connection is made via this MSDN code:
        private Socket ConnectSocket()
        {
            Socket s = null;
            IPHostEntry hostEntry = null;

            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);   // Can also use IP Address [127.0.0.1 = "localhost"] [Loopback network connection]

            // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach (IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipe = new IPEndPoint(address, port);
                Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                tempSocket.Connect(ipe);        // Need to add exception for target machine actively refusing port due to firewall

                if (tempSocket.Connected)
                {
                    s = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }                 
            }
            return s;
        }
What have I done wrong? Thanks

Share this post


Link to post
Share on other sites
I have a copy of Max/MSP with a udpreceive listening at port 7400.

BUT, if I change the code to ProtocolType.UDP then:

The requested protocol has not been configured into the system, or no implementation for it exists

:(

EDIT: Is that a way of catch these errors and returning them as text rather than the code breaking?

Share this post


Link to post
Share on other sites

This topic is 3044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this