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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:37:38+00:00 2026-05-27T06:37:38+00:00

This server can handle 2 types of clients one which request one shot data

  • 0

This server can handle 2 types of clients one which request one shot data transmission and another requested periodic data transmission.
It wait for control character from client to start and stop transmission.
For one shot ‘c’ start transmission and for periodic ‘a’ starts and ‘b’ stops it.
But as the execution comes to condition checking for ‘a’ the execution is halted there and child starts receiving unpredictable value like (0,32767).
When i checked with gdb than it also not showing any thing as come to “if(control==’a’)”.
Can u suggest me some thing to fix this problem.

     `while(1)
    {

        sin_size = sizeof(struct sockaddr_storage);

        connected = accept(sock1, (struct sockaddr *)&client_addr,&sin_size);
         //connecteds[count]=connected;
         //clients[count]=client_addr;
         if(connected == -1){
            perror("accept");
            continue;
           }
         count++;
         printf("\n%d %d\n",count,connected);
         inet_ntop(client_addr.ss_family,get_in_addr((struct sockaddr *)&client_addr),s, sizeof s);
         printf("server: got connection from %s\n", s);

         pid=fork();
         if(pid<0)perror("error in fork");

        if(pid==0)
        {
         while(1){
                 int no;
                 char control;
                 printf("\n waiting for data request from clients:.......\n");
                 fflush(stdout);
                 bzero(&control,1);
                 while(1){
                          bytes_recieved = recv(connected,&control,1,0);
                          if(control=='a'||control=='b'||control=='c')
                          break;
                         }
                          r1.control1=control;
                          r1.client=client_addr;
                          send(sock,&r1,sizeof(struct recieved),0);
                 printf("\nreceived data request is :%c from client (%s)\n", control,s);
                 fflush(stdout);
                 if(control=='a')
                   {printf("..................");
                    struct argument *argu;
                    argu->dis=connected;
                                         argu->sock=sock;
                    argu->cli=client_addr;

                   //inet_ntop(client_addr.ss_family,get_in_addr((struct sockaddr *)&client),s, sizeof s);
                    printf("transmission started for client:%s\n",s);
                    fflush(stdout);

                    pthread_create(&tid1,NULL,sends,(void*)argu);
                    pthread_create(&tid2,NULL,recieve,(void*)argu);

                    pthread_join(tid1,NULL);
                    pthread_join(tid2,NULL);

                    control=value;
                    printf("comming here\n");
                    fflush(stdout);
                   }
                 if(control=='b')
                   {
                    printf("terminating the connection with client (%s).\n",s);
                    fflush(stdout);
                    break;
                   }
                 if(control=='c')
                   {
                    while(1){
                             recv(sock,&data1,sizeof(struct dataset),0);
                             if(data1.data==200)
                             break;
                            }

                    send(connected,&data1,sizeof(struct dataset),0);

                    printf("getting data from server %c\n%d\nterminating the connection with client (%s).\n",data1.a,data1.data,s);
                    fflush(stdout);
                    break;
                   }
                }//end of while2
        }//end of child

`

  • 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-05-27T06:37:38+00:00Added an answer on May 27, 2026 at 6:37 am

    You do not allocate memory for the argu pointer.

    struct argument *argu = malloc(sizeof(struct argument));
    

    Remember to free the pointer after the two calls to pthread_join.

    Edit

    Better yet, instead of using a pointer, just use the structure:

    struct argument argu;
    
    argu.dis = connected;
    /* etc. */
    
    pthread_create(&tid1,NULL,sends,&argu);
    pthread_create(&tid2,NULL,recieve,&argu);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently in the process of programming a server which can let clients interact
In C# you can use verbatim strings like this: @\\server\share\file.txt Is there something similar
Anyone know of a control for asp.net that can achieve this either server or
With this code I can show an animated gif while the server script is
In SQL Server 2017, you can use this syntax, but not in earlier versions:
How can I fetch images from a server? I've got this bit of code
How can I upload files to server using JSP/Servlet? I tried this: <form action="upload"
SELECT name FROM sys.databases -- this can list all database name in the server
How can i download all directory from server recursively. I use WinINet and this
In SQL Server , I can do something like this: UPDATE tbl1 SET col2

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.