Server port gets down in Long idle time

Hi everyone,

I have written small Server app which accepts connections from clients. But what I notice is when the server gets idle for a long time, Clients can not connect meaning Server PORT is down even the process is still running. I made a NETSTAT on the PORT but no results prompted meaning PORT is down.

Any idea on this situation.

OS is AIX.
I will need to see the code to see what is going on.
ServerSocket::ServerSocket(int port)
{
iSockFD = 0;
listenfd = 0;
connfd = 0;
iServerPort = port;
// Initialise socket related varialbes
listenfd = socket(AF_INET, SOCK_STREAM, 0);
//bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(iServerPort);
if (bind(listenfd, (SA *) &servaddr, sizeof(servaddr)) != -1)
{
//cout << "Server Bind succeeded" << endl;
if (listen(listenfd, LISTENQ) != -1)
{
//cout << "Server listen successful" << endl;
}
else
{
perror("listen error: ");
//cout << "ERROR : Server listen failure,... exiting, try again!" << endl;
//FrameworkManager::printMsg("ERROR : Server listen failure,... exiting, try again!");
PRINT_MESSAGE("ERROR", "Server listen failure,... exiting, try again!");
exit(0);
}
}
else
{
perror("bind error: ");
//cout << "ERROR : Server bind error,... exiting, try again!" << endl;
//FrameworkManager::printMsg("ERROR : Server bind error,... exiting, try again!");
PRINT_MESSAGE("ERROR", "Server bind error,... exiting, try again!");
exit(0);
}

}// End cosntructor

ServerSocket::~ServerSocket(){}

// -------------------------------------------------------------------
// Simulate server accept method and fork
// new process for each client
// -------------------------------------------------------------------
int ServerSocket::acceptConnections()
{
clilen = sizeof(cliaddr);
//cout << "Accepting connections" << endl;
//FrameworkManager::printMsg("Accepting connections");
PRINT_MESSAGE_TIME("INFO ", "Accepting connections");

if((connfd = accept(listenfd, (SA *) &cliaddr, &clilen)) < 0)
{
perror("accept error: ");
//cout << "Server accept() error" << endl;
//FrameworkManager::printMsg("ERROR : Server accept() error");
PRINT_MESSAGE("ERROR", "Server accept() error");
}

iSockFD = connfd;
return connfd;

}// End method


// -------------------------------------------------------------------
// Accept connections and assign a descriptor reference
// -------------------------------------------------------------------
bool ServerSocket::acceptConnections(int &FD)
{
clilen = sizeof(cliaddr);
//FrameworkManager::printMsg("Accepting connections");
PRINT_MESSAGE_TIME("INFO ", "Accepting connections");

if((connfd = accept(listenfd, (SA *) &cliaddr, &clilen)) < 0)
{
perror("accept error: ");
//cout << "Server accept() error" << endl;
//FrameworkManager::printMsg("ERROR : Server accept() error");
PRINT_MESSAGE("ERROR", "Server accept() error");
return false;
}
else
{
iSockFD = connfd;
FD = connfd;

// Get the IP of the client
struct sockaddr_in newClientAddr;
int addrSize = sizeof(newClientAddr);
getpeername(connfd, (struct sockaddr *) &newClientAddr, (socklen_t *)&addrSize);

cout << "Client address : " << inet_ntoa(newClientAddr.sin_addr) << endl;
//FrameworkManager::printMsg("Client address : " + inet_ntoa(newClientAddr.sin_addr));
return true;
}

}// End method
Topic archived. No new replies allowed.