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

  • Home
  • SEARCH
  • 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 8550857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:35+00:00 2026-06-11T14:03:35+00:00

I am wanting to use select to receive and send on a client/server on

  • 0

I am wanting to use select to receive and send on a client/server on the same socket descriptor (serverside).

timestruct* myTime;
sockfd = accept(listeningFd, 0, 0);

while(1)
    FD_ZERO(&my_fd_set)
    maxFd = sockfd
    FD_ZERO(&my_fd_set);
    FD_SET(sockfd, &my_fd_set);
    select(maxFd+1, &my_fd_set, &my_fd_set, NULL, myTime);

    for (j=0; j<=maxFd; j++)

    if(FD_ISSET(j, &temp_fd_set))
        if(j==sockfd)
            send()
        if(j==sockfd)
            recv()

This is essentially what I want to do. Obviously this won’t work because sockfd is going to be the same value for sending and receiving. Is there a way I can do this without using fork()??
Currently I have a blocking recv and send but the server could be required to recv multiple commands while another command is being processed to send back to the client.
I am very knew to c and also ‘select()’. Because select has the three fd_set options (read, write, execute) I thought maybe I could do this.

Thank you.

  • 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-11T14:03:37+00:00Added an answer on June 11, 2026 at 2:03 pm

    Use different sets for the rfds and wfds parameters to select, so you can distinguish when sockfd is in one set but not the other.

    fd_set rfds;
    fd_set wfds;
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    
    FD_SET(sockfd, &rfds);
    FD_SET(sockfd, &wfds);
    if(select(sockfd + 1, &rfds, &wfds, NULL, myTime) < 0) {
        perror("select");
        return -1;
    }
    
    if(FD_ISSET(sockfd, &rfds))
        recv();
    if(FD_ISSET(sockfd, &wfds))
        send();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting to use a php variable as the destination email for Amazon SES
I'm wanting to use two Objective-C libraries in a MonoTouch app: the Facebook library
I am wanting to use jquery to do a show/hide of a DIV from
I'm wanting to use the jquery dialog to open a modal dialog, and in
When dealing with a series of numbers, and wanting to use hash results for
Stuck on KVCs in Obj-C again. I am wanting to use KVC to find
Here is the jsFiddle: http://jsfiddle.net/JFwDw/2/ What I'm wanting to do is use links to
I am wanting to use the g:timeZoneSelect tag within my application, problem is im
I am wanting to use settimeout to delay the closing of the menu slightly
I'm wanting to select rows in a table where the primary key is in

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.