Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:33:15+00:00 2026-06-05T19:33:15+00:00

I am building a client that can recieve information from the server and from

  • 0

I am building a client that can recieve information from the server and from the user (stdin), so I am using select to monitor both. What happens is that is a keyboard input is monitored the I send a message to the client and get one back, no problem. But when the server send a message nothing happens, and I don’t know why. Is using select() the proper way to do so?

Here’s my code:

void readSocket(fd_set tempfd) {
    const char * tweet, * inMessage;
    if (FD_ISSET(srverfd,&tempfd)) {
        inMessage = getMessage();
        printSystemMessages(inMessage);
    }

    if (FD_ISSET(STDIN_FILENO,&tempfd)) {
        tweet = getUserTweet();
        sendMessage(tweet);
        inMessage = getMessage();
        if (strcmp(inMessage,OK) != 0) {
            printSystemMessages(inMessage);
        }
        if (strcmp(inMessage,EXIT) == 0) {
            return;
        }
    }
    return;
}

int main (int argc, char *argv[] ){
    int value;
    bool clientON = false;
    fd_set tempfd;

    if(establishConnection(argv[2],argv[3])){
        cerr << "usage: failed to make connection" << endl << "exiting..." << endl;
        exit(EXIT_FAILURE);
    }

    cout << "Connected successfully" << endl;
    sendMessage("CONNECT "+clientName); //Connect
    if(strcmp(getMessage(),OK) == 0){
        build_select_list();
        printSystemMessages("Welcome!");
        clientON = true;
        cout<< man <<endl;
    }
    while(clientON){
        tempfd = inputFdSet;
        printTweetFormat("TweetMy:");

        value = select(maxSock, &tempfd, NULL, NULL, NULL);
        if (value < 0) {
            perror("select");
            exit(EXIT_FAILURE);
        }
        if (value == 0) {
            continue;
        }
        else {
            readSocket(tempfd);
        }
    }
    close(srverfd);

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:33:17+00:00Added an answer on June 5, 2026 at 7:33 pm

    This might help you – pass maxSock+1 instead of maxSock to your select() call;

    From the man page on select()

         nfds  is the highest-numbered file descriptor in any of the three sets,
          plus 1.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building 2 programs (client/server) that communicate through FIFOs. Both programs have threads. When
I'm building Java client that will automatically upload file from Java server to Panda
I'm building a client that talks to the http server. Now my client needs
I'm building a .NET remoting client/server that will be transmitting thousands of files, of
I'm building a CD for a client that contains a video training course. I
We're building an application that is a Silverlight client application, but we've created an
I am building a small app that uses backbone.js on the client side, node.js/socket.io
I'm building a simple client-server chat system. The clients send data to the server
I am building an AJAX application that uses both HTTP Content and HTTP Header
We're building a set of external web services to be consumed client-side (using jquery/AJAX)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.