I’m using winsock and I open my sockets in the standard way (I handle errors correctly, but for the sake of this question I’ve made the code brief);
SOCKET sSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
If I then connect it like so, it may lose connection occasionally.
connect(sSocket, reinterpret_cast<SOCKADDR*>(&sinAddr), sizeof(sinAddr));
When this happens, do I need to close and re-create the socket, or should I just re-call connect() ?
After a socket has been
close()ed, it can not be used anymore.Or the other way round: As long as
close()has not been called on a socket, it can be (re-)used.The call to
socket()allocates a socket descriptor to the calling process. The socket descriptor exists and stays assigned to the process untilclose()is called.