Home > Net >  accept() call on server is successful but connect() call on client failed with error code 10035
accept() call on server is successful but connect() call on client failed with error code 10035

Time:07-06

I've a client server model operating in non blocking mode where the server is as usual trying to accept connections infinitely. And client is repeatedly trying to connect with the server until it succeeds. When I run the server first and then client, I can see logs on server that the accept() call was a success but on client side the connect() call is failing with an error code 10035.

Overall files are a lot bigger than than this and there's so much going on in them. Both server & client are actually packet sniffers and the problematic part is when I try to establish a connection between these 2 sniffers to transfer information.

CodePudding user response:

According to me connect() takes some time to establish a connection thus you cannot have it running in non blocking mode. And server is showing no error in accept() is because of the following reason: 3 way handshake: Client sends SYN flag to the server And server responds with SYN-ACK and when server acknowledges, it returns success from accept() BUT, to complete 3 way handshake, client must send an ACK back to the server which it fails to do because of non blocking mode, thus connect() fails.

CodePudding user response:

Error code 10035 is WSAEWOULDBLOCK (table), which means the connection did not fail -- it just hasn't completed yet, and you need to wait a bit.

Normally one will wait until the socket is writable or has an error condition after issuing a connect that returns this code -- once one of those two things happen, you know the connection has either completed or failed for some other reason. You can do that wait with a select call with the descriptor included in 'writefds' and 'exceptfds' arguments.

  • Related