Thread: [newb] how to use threads with sockets ?

  1. #1
    Registered User
    Join Date
    Apr 2007

    [newb] how to use threads with sockets ?

    [Newb alert]
    i wish to start a server that will allow multipile connections at once at first i thout about forking but then i realized that it will consume alot of resorses.

    so i started googling about threads and i thout that it is wiser to use threads for this condition .
    as from example on socket for linux tutorial

    while (1)
       newsockfd = accept(sockfd,
                   (struct sockaddr *) &cli_addr, &clilen);
       if (newsockfd < 0)
         error("ERROR on accept");
       pid = fork();
       if (pid < 0)
         error("ERROR on fork");
       if (pid === 0)
     } /* end of while */
    what will be the apropreate code with treads ?

    my server will get a string from a uniqe client accses a database retrive a aporeate data from database
    start sevral function on this data
    and return an answer to the client
    why Gaos didn't had a wife ?

  2. #2
    Registered User
    Join Date
    Aug 2007
    Page four of the following PDF has a short introduction on threading a server:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  2. Programming chat client, need some help (sockets & threads)
    By lalilulelo17 in forum Linux Programming
    Replies: 1
    Last Post: 04-19-2008, 04:01 AM
  3. Sharing sockets among threads
    By Hawkin in forum Networking/Device Communication
    Replies: 19
    Last Post: 02-04-2008, 04:13 PM
  4. Library for pool, sockets, threads
    By Mortissus in forum C++ Programming
    Replies: 13
    Last Post: 07-14-2007, 07:41 AM
  5. Sockets and threads
    By karas in forum Linux Programming
    Replies: 4
    Last Post: 06-21-2007, 03:33 AM