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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:33:43+00:00 2026-05-22T16:33:43+00:00

I have a program in c++ that sends a socket of 23723 bytes to

  • 0

I have a program in c++ that sends a socket of 23723 bytes to a flash player in one “shot”.

The flash player sometimes receives two packets of size 17520 and 6203, and other times it receives a single packet of 23723.

EDIT: There does not seem to be a way to obtain the total number of bytes associated with the send data from flash. This would make it very difficult to build a loop to reconstruct the “broken” packet.

I thought TCP was supposed to correctly recombine the packets and I am having difficulty recombining them myself.

This is my receiving handler in flash:

var socket:Socket = new Socket();
socket.addEventListener(Event.CONNECT, socketConnectHandler);
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataReceivedHandler);
socket.connect("127.0.0.1", 7445);
socket.writeUTFBytes("hi");

private function socketDataReceivedHandler(event:ProgressEvent):void {
  var socket:Socket = event.target as Socket;
  trace(socket.bytesAvailable);
  var data:ByteArray = new ByteArray();
  socket.readBytes(data);
}

The command:

trace(socket.bytesAvailable);

will at times print 23723, and at other times, will print 17520 quickly followed by 6203. The total size are just examples and are subject to change for each send sockets. Also many sockets can be sent or received at the same time, so the split packets can be inter-mixed. In c++ I could determine what the total size of the sent data was, even if I did not receive the whole sent data yet.

  • 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-22T16:33:44+00:00Added an answer on May 22, 2026 at 4:33 pm

    This has nothing to do with tcp. The socket can send you any number of bytes as long as it is at least one byte. So you might get [1, 23722]. The correct way to do this is to call read in a loop and fill an array yourself. If your code does not contain a loop but works, then it works by accident. This cannot work without a loop.

    Edit: do not use bytesAvailable. Check the return value of the read function. Check your code: If your code relies on bytesAvailable it is wrong.

    Edit2: Looks like the flash api (which I do not know) works differently from the socket api that all other frameworks and languages use. I assumed it would work the same, so let me correct: You are supposed to have the following loop:

    int writePos = 0;
    var array = ...;
    while true:
     wait for bytes to become available. i do not know how to do this but one method would be 'while bytesAvailable == 0 then sleep 10'
     var bytesAvailableCopy = bytesAvailable; //copy because this value can change anytime
     socket.read(array, writePos, bytesAvailableCopy );
     writePos += bytesAvailableCopy;
     if(writePos == maxLength) break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple file transfer socket program where one socket sends file data
I am writing a Perl program that sends and receives messages from two sockets
I have a small program that sends and receives data from server and client
I have a C program that do recv/send operations from/to socket using a for(;;)
I have a basic ruby program, that listens on a port (53), receives the
I have a program that sends data to the home IP to the port####.
I have one program that calls one tar.. something like popen(tar -zcvf) I want
I want to create a server and client that sends and receives UDP packets
I have a program that can send text to any other program for further
Hey guys, I have a program that uses ajax to send a post to

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.