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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:27:27+00:00 2026-05-30T22:27:27+00:00

I am working on a client-server project and need to implement a logic where

  • 0

I am working on a client-server project and need to implement a logic where I need to check whether I have received the last data over a TCP socket connection, before I proceed.
To make sure that I have received all the data , I am planning to pad a flag to the last packet sent.I had two options in mind as below and also related prob.

i. Use a struct as below and populate the vst_pad for the last packet sent and check the same on the recv side for its presence. The advantage over option two is that, I dont have to remove the flag from actual data before writing it to a file.Just check the first member of the struct

typedef struct
   {
    /* String holding padding for last packet when socket is changed */
    char vst_pad[10];
    /* Pointer to data being transmitted */
    char *vst_data;
    //unsigned char vst_data[1];
   } st_packetData;

The problem is I have to serialize the struct on every send call. Also I am not sure whether I will receive the entire struct over TCP in one recv call and so have to add logic/overhead to check this every time. I have implemented this so far but figured it later that stream based TCP may not guarantee to recv entire struct in one call.

ii. Use function like strncat to add that flag at the end to the last data being sent.

The prob is I have to check on every receive call either using regex functions or function like strstr for the presence of that flag and if so have to remove it from the data.

This application is going to be used for large data transfers and hence want to add minimal overhead on every send/recv/read/write call. Would really appreciate to know if there is a better option then the above two or any other option to check the receipt of last packet. The program is multithreaded.

Edit: I do not know the total size of file I am going to send, but I am sending fixed amount of data. That is fgets read until the size specified -1 or until a new line is encountered.

  • 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-30T22:27:29+00:00Added an answer on May 30, 2026 at 10:27 pm

    Do you know the size of the data in advance, and is it a requirement that you implement a end of message flag?

    Because I would simplify the design, add a 4-byte header (assuming you’re not sending more than 4gb of data per message), that contains the expected size of the message.

    Thus you parse out the first 4 bytes, calculate the size, then continue calling recv until you get that much data.

    You’ll need to handle the case where your recv call gets data from the next message, and obviously error handling.

    Another issue not raised with your 10byte pad solution is what happens if the actual message contains 10 zero bytes–assuming you’re padding it with zeros? You’d need to escape the 10bytes of zeros otherwise you may mistakenly truncate the message.

    Using a fixed sized header and a known size value will alleviate this problem.

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

Sidebar

Related Questions

I'm working on this project where the client has a virtual server setup. I
I am working on a simple client-server project. Client is written in Java, it
I'm working on a server project in C#, and after a TCP message is
I'm working on my C# client server application for school, and I have a
Im working on a project where i need to use socket.io at client end
I have an Android project where I need to build a client app to
I'm currently working on a small client/server project that uses CORBA and I am
I am working on grails project where I need to apply server side validations.
i'm working on a project where i have an embedded jetty server for serving
I am working on a client-server application that uses boost::serialization library for it's serialization

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.