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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:21:30+00:00 2026-06-16T09:21:30+00:00

This is for educational purpose (University assignment). I need to write a client-server programs

  • 0

This is for educational purpose (University assignment).

I need to write a client-server programs in C for Linux. (I already have that part. A client connects to the server, it sends and receive files without a problem…).

When a client connects to the server, it sends the server a list of files on the client. So the server has a list of all the files on it’s clients.

A client A can request from the server a file “test.txt”, the server knows that the file is on client B, and the file should be transferred from B to A. I’m trying to think about the best way of doing this.

  1. recv from B into a buffer, and immediatly send() the buffer to A?
  2. recv() the whole file from B and save it on server ,then send it
    to A?

My programs should support this behavior:
if A asks a file from B, and then C asks a file from B, C should NOT wait until the transfer A<–>B will end. And this is where I get stuck.

Thank you very much!!

Edit: My server is using threads: whenever a new client is connecting, a new thread is opened to serve it. My client, at this moment, does not use threads (this can be changed).

  • 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-16T09:21:31+00:00Added an answer on June 16, 2026 at 9:21 am

    If you want to do several transfers at once using sockets you have two options:

    Blocking sockets and threads

    This is the way you’ve written your server. The problem with threads is that they can lead to bugs that are rather hard to debug. Combine that with network bugs that in themselves can be rather hard to debug and you have a potential nightmarish debugging session on your hands.

    Non-blocking sockets and select()

    This way doesn’t need threads, instead it uses select() to see which sockets have data waiting to be read. Combine that with some loops and you can transfer several files concurrently. Setting sockets to be non-blocking is easy, using correct can be slightly trickier but weighted against the potential for thread + network bugs this is the way I personally prefer to write network code.

    Regarding your actual problem; I would suggest something like this:

    Client A connects to server S. You need to bind the local side for the next step.
    A also opens another socket for data transfer on the next port upwards.
    S sends file list to A. How you build up the file list I leave to you.
    A requests file F from S.
    S checks which client has F.
    S sends "send F to A on port X" to B. You can check which remote port is used, and then you know which port to send the file on.
    B recieves and executes the command.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It comes when I want to write my own quicksort for educational purpose. This
I have an educational site that serves up curriculum based upon Grade level. The
I want to write a simple compiler for educational purposes in Delphi. I have
so i am developing my own download manager for educational purpose. I have multiple
I am trying to write an audio fingerprinting library for educational purpose. Its based
For educational purposes I tried to make a server and client where the server
Context This is purely for education purposes. I want to write a primitive database.
This should be a simple one: I have an observableArray object called To in
I'd like to write an Objective-C class without Cocoa or GNU's Object.h (for educational
For educational purposes I have set up a project layout like so (flat in

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.