I inherited the TCP code that called:
bind(tcpSocket, (struct sockaddr*)&server_addr, sizeof(server_addr));
before calling
setsockopt(tcpSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
Not surprisingly, this led to the message: "The address is already in use." Just changing the order of the calls resolved the problem.
The question arises: in the general case, should I make any calls setsockopt()before the call bind()? Before the challenge connect()?
source
share