What could be the reasons for the refusal refused?

I am trying to write a server program in C using another client, I get this error when I try to connect via port 2080, for example.

connection refused 

What could be the reasons for this error?

+94
c sockets connection-refused
Feb 25 '10 at 10:55
source share
11 answers

There may be many reasons, but the most common are:

  • The port is not open on the destination machine.

  • The port is open on the destination machine, but its gap from the pending connections is filled.

  • The firewall between the client and server blocks access (also checks for local firewalls).

After checking the firewalls and opening the port, use telnet to connect to ip / port to verify connectivity. This fixes any potential problems from your application.

+78
Feb 25 '10 at 11:02
source share

The error means that the listening socket OS recognized the incoming connection request, but preferred to reject it intentionally.

Assuming the intermediate firewall is not interfering, there are only two reasons (I know) for the OS to reject the incoming connection request. One of the reasons has already been mentioned several times - the plug-in listening port is not open.

There is another reason that has not yet been mentioned - the listening port is actually open and actively used, but its lag from the requests for incoming connections in the queue has reached a maximum, so there is no room for requesting an incoming connection queued at that moment. Server code has not yet called accept () to complete the cleanup of available slots for new queue items.

Wait a while and try again. Unfortunately, there is no way to distinguish between "port is not open at all" and "port is open, but too busy right now." They both use the same common error code.

+65
Mar 02 '10 at 8:37
source share

If you try to open a TCP connection with another host and you see a "Connection refused" error message, it means that

  • You have sent a TCP SYN packet to another host.
  • Then you received a TCP RST packet in response.

RST bit in a TCP packet that indicates that the connection should be reset. This usually means that another host has received a connection attempt and is actively rejecting your TCP connection, but sometimes an intermediate firewall can block your TCP SYN packet and send you a TCP RST.

See https://tools.ietf.org/html/rfc793 page 69:

SYN-RECEIVED STATE

  If the RST bit is set If this connection was initiated with a passive OPEN (ie, came from the LISTEN state), then return this connection to LISTEN state and return. The user need not be informed. If this connection was initiated with an active OPEN (ie, came from SYN-SENT state) then the connection was refused, signal the user "connection refused". In either case, all segments on the retransmission queue should be removed. And in the active OPEN case, enter the CLOSED state and delete the TCB, and return. 
+19
Apr 30 '14 at 9:28
source share

A connection rejected means that the port you are trying to connect to is not actually open.

Thus, either you are connecting to the wrong IP address, or to the wrong port, or the server is listening on the wrong port or actually not working.

A common mistake is not to indicate the port number when binding or connecting in network byte order ...

+8
Feb 25 '10 at 11:03
source share

Check on the server side that it is listening on port 2080. First, try to confirm this on the server machine by sending telnet to this port:

telnet localhost 2080

If he listens, he can answer.

+5
Feb 25 '10 at
source share

Although this does not look like your situation, sometimes a connection failure may also indicate a conflict of IP addresses on your network. You can find possible ip conflicts by doing:

  arp-scan -I eth0 -l | grep <ipaddress> 

and

 arping <ipaddress> 

This AskUbuntu question also contains additional information.

+1
Jan 15 '13 at 17:35
source share

1. Check the status of your server.

2. Check the port status.

For example, 3306 netstat -nupl|grep 3306 .

3. Check your firewalls. For example, add 3306

 vim /etc/sysconfig/iptables # add -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT 
+1
Mar 24 '17 at 4:10
source share

From the point of view of the Checkpoint firewall, you will see a message from the firewall if you actually select “Reject as action”, thereby exposing the intended attacker to have a firewall in front of the server. The firewall will disable all connections that do not match the policy. Connection refused almost always from the server

0
Sep 29 '12 at 16:20
source share

I have the same problem with my working computer. The problem is that when you enter localhost, it goes to the proxy address and not the local address that you should bypass it, follow these steps.

Chrome => Settings => Change proxy server settings => LAN settings => check bypass proxy server for local addresses.

0
Aug 21 '13 at 6:03
source share

In Ubuntu, try sudo ufw allow <port_number> to access the firewall on your server and db.

0
May 14 '17 at 5:59 a.m.
source share

I had the same message with a completely different reason: wsock32.dll not found. Call ::socket(PF_INET, SOCK_STREAM, 0); kept returning INVALID_SOCKET , but the reason is that the winsock dll was not loaded.

In the end, I started the Sysinternals process monitor and noticed that it was looking for the DLL "everywhere", but could not find it.

Silent failures are great!

-one
03 Oct '16 at 13:55 on
source share



All Articles