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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:57:15+00:00 2026-05-29T18:57:15+00:00

static void HandlePackets(void* pParams) { int iResult = 0; char recvbuf[MAX_PACKET_LENGTH]; printf(Packet handling started\n);

  • 0
static void HandlePackets(void* pParams)
{
   int iResult = 0;
   char recvbuf[MAX_PACKET_LENGTH];

   printf("Packet handling started\n");

   while((iResult = recv(lhSocket, recvbuf, MAX_PACKET_LENGTH, 0)) > 0)
      printf("Bytes received: %d\n", iResult);

   printf("Packet handling stopped with reason %i", WSAGetLastError());
}

For now, it only prints the amount of bytes received.

Could such things happen, that recv will receive only a half of packet? Or one full packet and half of next packet, if server sent them one by one fast?

For example, server sent a single packet with 512 bytes length, is it possible that recv first got 500 bytes, and the remain 12 will receive from second attempt?

If server sending a lot of packets with 512 bytes length for each, is it possible that recv will get 700 bytes from first executing and the remain bytes from second?

MAX_PACKET_LENGTH is 1024

(I talk here about application layer packets, not transport layer.)

The whole problem is – do I need to make some possibility for client to combine received bytes into one packet or split over-received bytes to different packets?

  • 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-29T18:57:18+00:00Added an answer on May 29, 2026 at 6:57 pm

    Is it possible that recv first got 500 bytes, and the remain 12 will receive from second attempt?

    Yes, definitely.

    You have no guarantee that, when the sending end sends a burst of X bytes, that the receiving end will pick them all up in a single call to recv. recv doesn’t even know how many bytes are in your application-layer “packet”.

    The whole problem is – do I need to make some possibility for client to combine received bytes into one packet or split over-received bytes to different packets?

    Your application will definitely have to accumulate data from possibly sequential reads, fill up a buffer, and implement parsing to look for a full packet.

    TCP/IP doesn’t know your application’s protocol; as David said, if you want to split the incoming data stream into “packets” then you must do that yourself.

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

Sidebar

Related Questions

public static void ejemplosString(String palabra){ char[] letras = palabra.toCharArray(); int contadorVocales = 0; for
static void Main() { string str; str = Console.ReadLine(); while (str != null)//HERE! {
public static void fillCheckList(string ListType,int RecordNum,CheckBox chkRequired,TextBox txtComplete,TextBox txtMemo) { string sql_Check = String.Format(@SELECT
public static void main(String[] args) { staples[] stemp = new staples[8]; int j; try
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat =
public static void main(String[] args) { int x = 1 + + + +
static void Job(Args _args) { int number=10; do { print (strfmt(current number = %1,
public static void main(String[] args) { System.out.println(fun(2,3,4)); } static int fun(int a,int b,int c)
public static void main (String[] args) { System.out.println(factorial(5)); } public int factorial(int n) {
public static void bubbleSort(Farm a[], int n) { String[] animals = getString(a); for(int i

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.