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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:00:41+00:00 2026-06-01T14:00:41+00:00

I need to create a server which creates a new thread for each client

  • 0

I need to create a server which creates a new thread for each client trying to connect to the server. The new thread created for each client manages the client and the server process listens for new connections from the port.

I need to code in Unix C. This is a sub-task of the task I need to finish as soon as possible. I am new to this field and hence do not know much about creating servers.

  • 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-01T14:00:43+00:00Added an answer on June 1, 2026 at 2:00 pm

    Basically, what you’re looking for is something like this :

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <pthread.h>
    
    void* handle_connection(void *arg)
    {
        int client_sock = *(int*)arg;
        /* handle the connection using the socket... */
    }
    
    int main(void)
    {
        /* do the necessary setup, i.e. bind() and listen()... */
        int client_sock;
        pthread_t client_threadid;
        while((client_sock = accept(server_sock, addr, addrlen)) != -1)
        {
            pthread_create(&client_threadid,NULL,handle_connection,&client_sock);
        }
    }
    

    This is a pretty basic skeleton for a server application which creates a different thread for every incoming client connection. If you don’t know what bind, listen, or accept is, then consult the second section of your local manual.

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

Sidebar

Related Questions

I am writing a small server which creates a new thread to handle each
I need to create a server socket, which should reject a connect request, if
Need to create a custom DNS name server using C which will check against
I need to create an out-of-process COM server (.exe) in C# that will be
I need to create an entirely new Sql Server 2008 database and want to
I need to create a repeatable process for deploying SQL Server Reporting Services reports.
I need to write a server which accepts connections from multiple client machines, maintains
on my server i've got an xml file for each client which holds the
I have a server to which multiple clients can connect to. The client is
I'm trying to create an Android client for a client/server app that has previously

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.