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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:13:51+00:00 2026-06-17T21:13:51+00:00

I am trying to receive a jpeg image from my c# server. The weird

  • 0

I am trying to receive a jpeg image from my c# server. The weird thing is when I run it with the debugger and have a break point anywhere in the method it works perfectly fine. Without a breakpoint then I get this error

Corrupt JPEG data: premature end of data segment

Here is my code

(void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
NSMutableData *data;
data = [NSMutableData new];
switch(eventCode) {
    case NSStreamEventHasBytesAvailable:
    {
        uint8_t buffer[1024];
        int len;

        while([inputStream hasBytesAvailable]) {
            len = [inputStream read:buffer maxLength:sizeof(buffer)];

            if (len > 0)
            {
                [data appendBytes:(const void*)buffer length:sizeof(buffer)];
            }
        }
        UIImage *images = [[UIImage alloc]initWithData:data];
        [dvdCover setImage:images];
    } break;
    case NSStreamEventEndEncountered:
    {
        //UIImage *images = [[UIImage alloc]initWithData:data];
        //[dvdCover setImage:images];


    } break;
}

}

  • 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-06-17T21:13:52+00:00Added an answer on June 17, 2026 at 9:13 pm
    hi you can check this code hop it will help you...
    
    case NSStreamEventHasBytesAvailable:
    {
    
    uint32_t max_size = 1000000;  // Max size of the received imaged you can modify it as your reqirement.
            NSMutableData* buffer = [[NSMutableData alloc] initWithLength: max_size];
            NSInteger totalBytesRead = 0;
            NSInteger bytesRead = [(NSInputStream *)stream read: [buffer mutableBytes] maxLength: max_size];
            if (bytesRead != 0) {
                while (bytesRead > 0 && totalBytesRead + bytesRead < max_size) {
                    totalBytesRead+= bytesRead;
                    bytesRead = [(NSInputStream *)stream read: [buffer mutableBytes] + totalBytesRead maxLength: max_size - totalBytesRead];
                }
                if (bytesRead >= 0) {
                    totalBytesRead += bytesRead;
                }
                else {
                    // read failure, report error and bail (not forgetting to release buffer)
                }
                [buffer setLength: totalBytesRead];
                yourImageName.image = [UIImage imageWithData: buffer];
                [buffer release];
    
    }  break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method where i am trying to receive an arraylist from another
I'm trying to receive JMS messages from a GlassFish (2.1) server remotely. I have
I am trying to receive an image from the Android Gallery via an ACTION_SEND
I'm trying to receive some data from a client in a server using Google
I have been trying to receive a data packet from a client however during
I've been trying to receive data on a server socket from a client with
I'm trying to receive an image from a user and then upload it to
I am trying to receive the image form Server and want to display it
I am trying to receive a json object back from php after sending data
I am trying to receive the url image and post the image into base64

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.