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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:19:26+00:00 2026-05-28T01:19:26+00:00

I need to code for uploading a file from client to server. In client

  • 0

I need to code for uploading a file from client to server.

In client side, i have declared a structure,

typedef struct upload_file
{
 char *filename;
 char *filebuffer;
}upload_file;

I am getting filename from command line argument.

In main function, I am assigning the file name with structure variable.

upload_file.filename = argv[1];

Then I am reading the file content, putting into a buffer & copying that to structure’s buffer value.

strcpy(upld.buffer,tmp); //tmp is a buffer which will contain the file content

After that I am writing the structure into socket as follows,

 write(sd, &upld, sizeof(upld));

This part is fine with the client side. In the server side if I read the whole structure & how do i separate the file content & file name?

Also , the buffer value (i.e file content ) from client side is malloced & could it be available to server side?

How do to this?

Thanks in advance.

  • 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-05-28T01:19:27+00:00Added an answer on May 28, 2026 at 1:19 am

    Passing a structure with pointers in it is useless. The pointers themselves will be sent across but not the things they point to.

    What you need to do is marshal the data for transmission, something which the various RPC mechanisms (OPC, DCE, etc) do quite well.

    If you can’t use an established method like that, it’s basically a matter of going through the structure element by element, copying the targets into a destination buffer.

    For example, with the structure:

    struct person {
        int age;
        char *name;
        char *addr;
    } p;
    

    you could do something like:

    msgbuff = outbuff = malloc (
        sizeof (int) +
        strlen (p.name) + 1 +
        strlen (p.addr) + 1
        );
    if (msgbuff != NULL) {
        *((int*)outbuff) = p.age;  outbuf += sizeof (p.age);
        strcpy (outbuff, p.name) ; outbuf += strlen (p.name) + 1;
        strcpy (outbuff, p.addr) ; outbuf += strlen (p.addr) + 1;
        // Send msgbuff
        free (msgbuff);
    } else {
        // Some error condition.
    }
    

    Note that an int is transferred directly since it’s in the structure. For the character pointers (C strings), you have to get at the target of the pointer rather than the pointer itself.

    Essentially, you transform:

    p:  age  (46)
        name (0x11111111)  -->  0x11111111: "paxdiablo"
        addr (0x22222222)  -->  0x22222222: "Circle 9, Hades"
       |--------------------|-------------------------------|
        structure memory <- | -> other memory
    

    into:

    msgbuff (0x88888888) -> {age}{"paxdiablo"}{"Circle 9, Hades"}
    

    This complicates the process a little since you also have to unmarshal at the other end, and you’ll need to watch out for system that have different sized int types. But that’s basically how it’s done.

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

Sidebar

Related Questions

I have a piece of code that allow users download file from server (document
I have got this JavaScript code for uploading files to my server (named it
I try to run code from this site http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/ but I have a problem,
How to create simple PHP COMET server page displaying current time? I need code
I need some code to download a pdf file. what i mean is normaly
I have a .NET 3.5 website that is uploading files to a SQL Server
Hi I need to get the name of the file the user selects from
I have a file called 'LoginViewController' that needs to do an action from the
A client application is uploading an audio file in chunks to an MVC3 site.
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is

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.