Google Answers Logo
View Question
 
Q: POSIX Threads ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: POSIX Threads
Category: Computers > Programming
Asked by: salman1-ga
List Price: $10.00
Posted: 27 Apr 2003 23:35 PDT
Expires: 27 May 2003 23:35 PDT
Question ID: 196406
Hi:

I need a C source-code that implements a simulated client/server model
using POSIX threads. With the following requirements:

1) Multiple clients needs to be spawned using POSIX threads
2) There can be multiple servers or a single server (does not really
matter)
3) The communication channel between the client and the server has to
TCP or UDP using sockets.
4) The program must be executable in at least ONE of the following
OS': UNIX*, SOLARIS, LINUX*
5) What this program does is irrelevant. It could be a chat program or
anything as long as the above requirements are met.

Please note I am not asking you to write the program but rather find
one in the internet that is very similar to the above. That's why I
have such as a subdued price for this question. Also, I am willing to
be a little more flexible in terms of my specification given you let
me know what you have come across.

Finally, if you believe you can come up with the source-code given you
have more time, which means for an additional amount, please let me
know.

Thanks
Salman.

Clarification of Question by salman1-ga on 27 Apr 2003 23:39 PDT
I forgot to mention: The source-code must be complete and compilable.

Request for Question Clarification by dogbite-ga on 28 Apr 2003 20:29 PDT
Hello salman1-ga,

  I am very familiar with POSIX threads
  and networking code.  Unfortunately, I 
  am not aware of any code freely available 
  on the Internet that has both a server/
  client thread model and sockets.  The 
  server/client thread model examples that 
  I know of use mutexs and conditional signals 
  to pass and share data.

  I could write a custom example program for 
  you.  I would do it for $50. 

  Please let me know if you would like me
  to do that.

         dogbite-ga

Clarification of Question by salman1-ga on 28 Apr 2003 22:13 PDT
dogbite-ga,

Can you clarify what you mean by: "...custom example program...". Does
that mean you will write a program that meets all my requirements?

Request for Question Clarification by dogbite-ga on 28 Apr 2003 22:19 PDT
Hi salman1-ga,

  Yes, I will write a program that:

    1) is a single process with one "server"
       thread and several "client" threads,
    2) has client threads communicating with 
       the server thread using a UDP socket, and
    3) will work on linux.

  Will that suit your needs?

          dogbite-ga

Clarification of Question by salman1-ga on 29 Apr 2003 08:38 PDT
That's great dogbite-na. I realize I asked for either UDP/TCP -
however do you think you can use TCP instead [I would prefer that].
That would be great. If you can do that start working on it.

Thanks
Salman.

Clarification of Question by salman1-ga on 29 Apr 2003 08:39 PDT
One other thing, how do I give you the extra $40 bucks?

Request for Question Clarification by dogbite-ga on 29 Apr 2003 09:32 PDT
Hi salman1-ga,

  Yes, I could use TCP instead
  of UDP.  That isn't a problem.

  May I ask why you want to use
  sockets at all?  It seems that
  you kind of defeat the point of
  threads if you're not using shared
  memory to communicate.  Why not
  write the server and clients as
  separate processes if you're going
  to use sockets for communication?

  As for the $40 -- you can just put
  it in the "tip" box when you submit
  your review, after I submit the answer.

  Let me know about the sockets, and I'll
  go ahead and start working on it.  I can
  finish it within 1 day.

              dogbite-ga

Clarification of Question by salman1-ga on 29 Apr 2003 10:32 PDT
Hey dogbite-ga:

Yes, you can separate the client and server into different processes
and possibly even separate executables. That's okay. However, the
clients (probably an array of them) *has to be* spawned using PThreads
and they [the clients] will send text-messages to the server. That's
about it.

Thanks
Salman.

Request for Question Clarification by dogbite-ga on 29 Apr 2003 12:17 PDT
Hey salman1-ga,

  Excellent. Just to be clear, we will
  now have two processes.  A server
  process and a client process.  The
  client process will have several
  threads, all of which create separate
  TCP connections with the server.

  Is that okay?

           dogbite-ga

Clarification of Question by salman1-ga on 29 Apr 2003 13:00 PDT
dogbite-ga,

Yes, that's perfect.
Answer  
Subject: Re: POSIX Threads
Answered By: dogbite-ga on 29 Apr 2003 13:43 PDT
Rated:5 out of 5 stars
 
Hello salman1-ga,

  Okay, I wrote the two programs
  and have put their source code here:

http://nms.lcs.mit.edu/~gch/google/clientserver.tar.gz

  The file also contains a README
  explaining how to use them.  The
  programs are a simple echo client
  and server -- the server sends back
  exactly what the clients send it.

  I hope the programs meet your needs exactly.

               dogbite-ga

Request for Answer Clarification by salman1-ga on 29 Apr 2003 14:40 PDT
Everything LOOKS PERFECT!!! Great great work.
Can you make one final change. Can you change client.c so that it
accepts through argv one argument which is the host name to the server
so that the client can send messages from different a machine? If it's
too much change forget it, and let me know.

You have done a lot - Thanks,
Salman.

Clarification of Answer by dogbite-ga on 29 Apr 2003 16:00 PDT
Hello salman1-ga,

  Okay, I made the change and have 
  updated the file here:

http://nms.lcs.mit.edu/~gch/google/clientserver.tar.gz

  It optionally takes an IP address
  on the command line.  Note that it
  does not take a hostname because I
  didn't want to put the code in to
  resolve the name to an IP number.

  So now you can connect to any server.

  And, I'm glad you're happy with the code.
  For $50, I'm happy to write it for you. :-)

                dogbite-ga
salman1-ga rated this answer:5 out of 5 stars and gave an additional tip of: $40.00
Great work. Simple/Clear/Precise answer.

Comments  
Subject: Re: POSIX Threads
From: mrprim8-ga on 28 Apr 2003 02:24 PDT
 
This page covers building your own POSIX threads based server :
(provides source - a skeleton of a multithreaded server)

http://home.t-online.de/home/Andreas.Steinmetz/shared/svsock.html#top



Here is more complete source code (an instant messaging client/server)
(links to source at bottom of page) - based on POSIX threads & use
TCP/IP

http://www.webguys.com/Projects/wim/


And the following have POSIX threads related source code for
networking stuff, etc:

http://www.cis.temple.edu/~ingargio/cis307/software/v3.linux/
http://www.cis.temple.edu/~ingargio/cis307/software/butenhof/

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy