Forum Discussion
4 Replies
- Altera_Forum
Honored Contributor
It's done when you create the socket and I believe it is blocking by default...in most network stacks. Double-check your socket settings.
- Altera_Forum
Honored Contributor
Yes, the socket is blocking by default.
In order to set non-blocking mode you must call: setsockopt(your_socket, SOL_SOCKET, SO_NONBLOCK, &max_socket, sizeof(int)); IIRC you could also set the default behaviour in Nichestack configuration file ipport.h - Altera_Forum
Honored Contributor
Thanks for confirming that the connect() should block by default. For some unknown reason, in my case, it does not block.
I have tried to use setsockopt() to guarantee that the socket is setup as "blocking" but the connect() stills returns -1 if a server is not currently listening. By the way, my recv() call does block as expected. I'm going to continue to investigate why the connect() is not behaving as expected. I'm also going to check out the file "ipport.h". - Altera_Forum
Honored Contributor
After doing further investigation (using the debugger), the error causing the connect() to return -1 is ECONNREFUSED.
Of course, since there's no server listening for this client that would make sense but since the connect() should be blocked until the server is listening, why is the error ECONNREFUSED ?