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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:20+00:00 2026-05-29T11:20:20+00:00

I’m working with asyn sockets now. I have a callback function ‘onDataReceived’, which is

  • 0

I’m working with asyn sockets now. I have a callback function ‘onDataReceived’, which is triggered whenever I receive any data.

First I was getting a single char at a time, so I changed socketPacket data buffer to a big array. Now when ever I receive data, I get it all at once, but when I try to send a bigger file, it doesn’t work once it exceeds the array size.

My question is this. I have a multithreaded socket server. How can I determinate whenever all data is received? for example I need to send an image, I encode the image into base64 and contruct a command “BASE64IMAGE” and then server reads the string until it reaches END_OF_DATA? is there a better way to do it? thanks!

  • 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-29T11:20:21+00:00Added an answer on May 29, 2026 at 11:20 am

    My question is this. I have a multithreaded socket server. How can I determinate whenever all data is received?

    There are three standard options for sending a “message” (whether that’s an image or whatever – a whole blob of data which may be large):

    • One message per connection: you can detect the end of the message by the other end closing the connection
    • Some sort of “end-message” marker: as you read the data, you check for a special marker which indicates the end of the message. If the marker could occur naturally, you’ll need to escape it – and unescape as you read
    • A header indicating the size of the message before the actual data is sent – just read that many bytes

    Personally, I like the last option – it makes reading the data and being sure that you’ve got it all much simpler than the first two options. You can allocate the right amount of memory to receive the data before you start, etc. However, it doesn’t cope well when you don’t know the message size before you start. You can modify the scheme by having multiple “chunks” for a single message, where you send the chunk size then the data, and a chunk size of 0 indicates the end of the data.

    Note that if you’re transferring data over just a socket, and you don’t need it to be 7-bit clean ASCII, I wouldn’t convert to Base-64 first. Just transfer it as binary data – your code will be simpler and more efficient both in time and bandwidth.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.