Question

I have made a small windows service which i needs to get connected from my own localhost system but on running the application i am getting error as..

No connection could be made because the target machine actively refused it 127.0.0.1:8082

whereas it is perfectly working in Live ip and port numbers but i need to test it on localhost as i cant access the live running ip everytime..

Here is my code...

byte[] data = new byte[1024];
         string input, stringData;
         String ip = "127.0.0.1";
         Int32 port = 8082;
         string path = "D:\\";

            if (File.Exists("ipsettings.txt"))
            {
                File.Delete("ipsettings.txt");
            }
            IPAddress ipad = IPAddress.Parse(ip);
            IPEndPoint ipend = new IPEndPoint(ipad, port);
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                sock.Connect(ipend);

            }
            catch (Exception ex)
            {
                throw ex;
            }

I am getting error at this point..

 try
            {
                sock.Connect(ipend);

            }
            catch (Exception ex)
            {
                throw ex;
            }

Please help me to resolve the issue.. Thanks in advance..

Was it helpful?

Solution

whereas it is perfectly working in Live ip and port numbers

How do you know that? The error says the exact opposite. Noone is listening at that IP:port. Run tcpview from the sysinternals suite to know more. Note that listening on the machine's own IP address, like 192.168.55.55, and listening on 127.0.0.1, and listening on * (every address) are different things. When you connect to 127.0.0.1, it would connect successfully to the latter two, but not the first. It could also go wrong if the other end is listening on UDP, not TCP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top