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 9152579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:05:17+00:00 2026-06-17T12:05:17+00:00

I’ve ran into a problem with a simple TCP Client implemented using select. The

  • 0

I’ve ran into a problem with a simple TCP Client implemented using select.

The problem is that,at the second printf it only displays before it gets to the connect() function then waits for user input. Does connect block the rest of the program until i send something? (The TCP server is also implemented using select but i didn’t find anything wrong with it)
I’ve searched on the web and couldn’t find a cause or maybe i didn’t search for the right thing..

#include <includes.h>
int main()
{
int sfd;
fd_set rset;
char buff[1024]=" ";
char playerName[20]="";
int nameSet=0;
struct sockaddr_in server;
sfd= socket(AF_INET,SOCK_STREAM,0);

if(sfd<0)
 { printf("socket not created\n");   return 0; }
bzero(&server,sizeof(struct sockaddr_in));
server.sin_family=AF_INET;
server.sin_port=htons(2020);
inet_aton("127.0.0.1",&server.sin_addr);
  //here is the problem after %d which calls the connect() function
printf("Conexion returned:%d \n  Name:",connect(sfd,(struct sockaddr *)&server,sizeof(server)));
 for(;;)
 {
 bzero(buff,1024);

 FD_ZERO(&rset);
 FD_SET(0,&rset);
 FD_SET(sfd,&rset);
     if(select(sfd+1,&rset,NULL,NULL,NULL)<0)
     {
         printf("con-lost!\n");
         break;
     }

     if(FD_ISSET(0,&rset))
     {
     printf("Talk: \n");
     scanf("%s",buff);
     if(nameSet==0)
     {
         strcpy(playerName,buff);
         nameSet=1;
         printf("Hi:%s\n",playerName);
     }
         if(write(sfd,buff,strlen(buff)+10)<0)
         {
             break;
         }
     }

      if(FD_ISSET(sfd,&rset)>0)
     {
         if(read(sfd,buff,1024)<=0)
         {
         printf("con is off!\n");
         break;
         }
     printf("msg rcd %s\n",buff);
     }

   } //endfor
   close(sfd);
   return 0;
 } //endmain
  • 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-17T12:05:18+00:00Added an answer on June 17, 2026 at 12:05 pm

    The connect function, on a blocking socket, blocks until the connect operation succeeds or fails.

    You should be warned that using select with a blocking socket, which is what your program does, does not ensure that your program will not block. When you get a select hit, that does not guarantee that a future operation will not block.

    strlen(buff)+10
    

    What’s the reasoning behind the +10?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm making a simple page using Google Maps API 3. My first. One marker
I am currently running into a problem where an element is coming back from

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.