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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:56:17+00:00 2026-05-11T10:56:17+00:00

I want to send a UIImage to a server through a socket. a)I open

  • 0

I want to send a UIImage to a server through a socket.

a)I open the outputstream:

 - (IBAction)send:(id)sender {     NSURL *website = [NSURL URLWithString:str_IP];     NSHost *host = [NSHost hostWithName:[website host]];     [NSStream getStreamsToHost:host port:1100 inputStream:nil outputStream:&oStream];     [oStream retain];     [oStream setDelegate:self];     [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];     [oStream open]; } 

b) I write NSData to outputstream after open completed and handle the error if error occurs.

 - (void) stream: (NSStream *) stream handleEvent: (NSStreamEvent) eventCode {     //printf('EVENT: Start.\n');      switch(eventCode)     {             case NSStreamEventOpenCompleted:             {                 //printf('EVENT: Open completed.\n');                  if(stream == oStream)                     {                         //printf('Sending...\n');                         NSData *data = UIImageJPEGRepresentation(drawImage.image, 90);                         NSInteger x = [oStream write:[data bytes] maxLength:[data length]];                     }                  break;             }             case NSStreamEventEndEncountered:             {                 //printf('EVENT: End encountered.\n');                 break;             }             case NSStreamEventHasSpaceAvailable:             {                 //printf('EVENT: Has space available.\n');                 break;             }             case NSStreamEventHasBytesAvailable:             {                 //printf('EVENT: Has bytes available.\n');                 break;             }             case NSStreamEventErrorOccurred:             {                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@'Error Occurred'                                                                        message:nil                                                                 delegate:nil                                                                    cancelButtonTitle:@'OK'                                                                      otherButtonTitles:nil];                                    [alert show];                 [alert release];                 break;             }             case NSStreamEventNone:             {                 //printf('EVENT: None.\n');                 break;             }     }      //printf('EVENT: End.\n'); }  

When I run this code, NSStreamEventOpenCompleted and NSStreamEventErrorOccurred is called.The NSOutputStream’s write method was called successfully and all the data is not nil. But after the data is written to the oStream, the eventCode will change to NSStreamEventErrorOccurred.

So I think maybe it’s not the correct way to use [oStream write]. What’s the correct way to use this message then? I find this message returns an NSInteger of -1073748088, what might be the problem?

  • 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. 2026-05-11T10:56:18+00:00Added an answer on May 11, 2026 at 10:56 am

    You should be writing the data only after space becomes available in the output stream. When the stream finishes opening, it doesn’t always immediately have space available, so writing to it won’t work. If you move the write call to the NSStreamEventHasSpaceAvailable handler, it should succeed.

    Also, the computer on the other end of the socket has no way of knowing the length of the data you’re sending. Unless you’re signaling the end-of-data by closing the socket, you should explicitly send the data length along with the data:

    case NSStreamEventHasSpaceAvailable: {     if(stream == oStream)     {         NSData *data = UIImageJPEGRepresentation(drawImage.image, 90);         // Convert from host to network endianness         uint32_t length = (uint32_t)htonl([data length]);         // Don't forget to check the return value of 'write'         [oStream write:(uint8_t *)&length maxLength:4];         [oStream write:[data bytes] maxLength:length];     }     break; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Categories extend the original class, but they don't subclass it,… May 12, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer Haven't tested this, but it's something like: RewriteRule \.php$ -… May 12, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer "0:0:0:0:0:0:0:1" is the IPv6 loopback address as defined in RFC… May 12, 2026 at 12:54 pm

Related Questions

I want to convert a UIImage to an NSOutputStream and send it to a
I want to send the data of a UIImage to the server through a
I want to send a UIImage to a server with socket. I'm using this
I want to send a message to a thread and handle it in the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.