Click here to Skip to main content
13,352,175 members (72,888 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am connecting to port on 10001..on which no any other application is running.i have checked through command "netstat -anb" still its throwing an error "No connection could be made because the target machine actively refused it", also no firewall is set on my machine..please help as i am new to the sockets

Posted 12-Oct-12 5:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If there isn't a listener available for that port on the target machine, then the machine will refuse the connection. Do you have a valid listener on the target?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I have googled about it & found this solution, Hope it helps.

If this happens always, it literally means that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.

If it happens occasionally - you used the word "sometimes" - and retrying succeeds, it is likely because the server has a full 'backlog'.

When you are waiting to be accepted on a listening socket, you are placed in a backlog. This backlog is finite and quite short - values of 1, 2 or 3 are not unusual - and so the OS might be unable to queue your request for the 'accept' to consume.

The backlog is a parameter on the listen function - all languages and platforms have basically the same API in this regard, even the C# one. This parameter is often configurable if you control the server, and is likely read from some settings file or the registry. Investigate how to configure your server.

If you wrote the server, you might have heavy processing in the accept of your socket, and this can be better moved to a separate worker-thread so your accept is always ready to receive connections. There are various architecture choices you can explore that mitigate queuing up clients and processing them sequentially.

Regardless of whether you can increase the server backlog, you do need retry logic in your client code to cope with this issue - as even with a long backlog the server might be receiving lots of other requests on that port at that time.

There is a rare possibility where a NAT router would give this error should it's ports for mappings be exhausted. I think we can discard this possibility as too much of a long shot though, since the router has 64K simultaneous connections to the same destination address/port before exhaustion.

Mostly the problem lies in the Firewall, Antivirus etc..
Why don't you change the port number & check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100