Connection refused problem
I am trying to connect a port which has been listenning. I checked with netstat -tan and saw
tcp 0 0 0.0.0.0:2000 0.0.0.0:* LISTEN
There is no firewall. My code is a standart code :
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(2000);
if ((sockfd = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)) <0)
printf("ERROR opening socket\n");
if (connect(sockfd,(struct sockaddr *)&addr,sizeof(addr)) < 0)
printf("con failed %s",strerror(errno));
It gives the error "Connection Refused".
I looked at the wireshark log and saw that it is trying to connect any other port that is not been listenning. I can connect to the port with telnet.
What is wrong with this code?