Thread: Basic C Socket Program Client/Server text file content transmission! DESPERATE HELP!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Desperatenoob View Post
    Do you think it's wise for me to start by making it for a 1:1 relationship, then if I have time modifying it for more users? Or would it be better to just jump into 30:1?
    Good thinking! I would definitely start with 1:1.

    Then: vis, forking for each client, that is one possibility if you want to make the connection persist. Every time you accept() a client, that client gets a new socket. However, you probably don't really need a persistant connection if the exchange is something like client logs on, client asks for file, server sends file, done. In that case, you can simply wait with accept() in a loop that answers and deals with every incoming call, and disconnects when the request is complete -- this is how an internet server works, more or less. Altho apache does fork, it does not fork for every request*, and it does not maintain open connections -- every request opens a new socket, then closes it when the request is complete. This method will work for an "unlimited" number of clients, but they get served one at a time. I do not know if a forking model -- where in theory, near simultaneous requests will be dealt with in parallel -- is faster than one which goes thru them one at a time. Either way, with <30 clients asking for (small) text files there unlikely to be any relevant delays at all by the server.

    If possible tho, check with your prof to make sure he is not expecting a forking model.

    *it does use a thread for each request, which is almost the same thing, but the premise is still that the threads do not persist. I do not think threading or forking is necessary at this scale. Of course, you may as well learn both methods. Which one you use now is up to you, I don't know the details of the requirements.
    Last edited by MK27; 10-21-2009 at 09:12 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM
  4. Problems displaying content of a text file
    By melissa in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2001, 06:13 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM