Add the keep alive option for testing.

This commit is contained in:
Charles Descamps 2025-02-19 17:54:22 -07:00
parent 439d6b1bf7
commit f815889d15

View file

@ -17,6 +17,7 @@ int main(int argc, char **argv)
int socketEchoFD; int socketEchoFD;
int clientEchoFD; int clientEchoFD;
int reuseAddrOpt = 1; int reuseAddrOpt = 1;
int keepAliveOpt = 1;
char message[BUFFER_SIZE]; char message[BUFFER_SIZE];
int messageBytes; int messageBytes;
struct sockaddr_in serverAddr; struct sockaddr_in serverAddr;
@ -34,7 +35,8 @@ int main(int argc, char **argv)
// use the setsockopt function to make the socket accept different configurations // use the setsockopt function to make the socket accept different configurations
// allow for the reuse of the address/bind. // allow for the reuse of the address/bind.
setsockopt(socketEchoFD, SOL_SOCKET, SO_REUSEADDR, &reuseAddrOpt, sizeof(reuseAddrOpt)); setsockopt(socketEchoFD, SOL_SOCKET, SO_REUSEADDR, &reuseAddrOpt, sizeof(reuseAddrOpt));
// also need to set the socket to non-blocking using setsockopt? // also need to set the socket to keepalive using setsockopt
setsockopt(socketEchoFD, SOL_SOCKET, SO_KEEPALIVE, &keepAliveOpt, sizeof(keepAliveOpt));
// CODE HERE // CODE HERE
// bind the TCP socket to port 8888 / ECHOPORT // bind the TCP socket to port 8888 / ECHOPORT
serverAddr.sin_family = AF_INET; serverAddr.sin_family = AF_INET;