WSACONNREFUSED when connecting to server

Posted by Robert Mason on Stack Overflow See other posts from Stack Overflow or by Robert Mason
Published on 2010-05-01T19:45:44Z Indexed on 2010/05/01 19:47 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

I'm currently working on a server. I know that the client side is working (I can connect to www.google.com on port 80, for example), but the server is not functioning correctly. The socket has socket()ed, bind()ed, and listen()ed successfully and is on an accept loop. The only problem is that accept() doesn't seem to work. netstat shows that the server connection is running fine, as it prints the PID of the server process as LISTENING on the correct port. However, accept never returns. Accept just keeps running, and running, and if i try to connect to the port on localhost, i get a 10061 WSACONNREFUSED. I tried looping the connection, and it just keeps refusing connections until i hit ctrl+c. I put a breakpoint directly after the call to accept(), and no matter how many times i try to connect to that port, the breakpoint never fires.

Why is accept not accepting connections? Has anyone else had this problem before?

Known:

[breakpoint0]
if ((new_fd = accept(sockint, NULL, NULL)) == -1) {
   throw netlib::error("Accept Error"); //netlib::error : public std::exception
}
else {
   [breakpoint1]
   code...;
}

breakpoint0 is reached (and then continued through), no exception is thrown, and breakpoint1 is never reached. The client code is proven to work. Netstat shows that the socket is listening.

If it means anything, i'm connecting to 127.0.0.1 on port 5842 (random number). The server is configured to run on 5842, and netstat confirms that the port is correct.

© Stack Overflow or respective owner

Related posts about c++

Related posts about winsock