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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:34+00:00 2026-05-23T08:18:34+00:00

I’ve created a small app which should send a NSString to my server. I’ve

  • 0

I’ve created a small app which should send a NSString to my server. I’ve got an application running there, which listens to an extact port and acts like a dumpster: it saves all the data which comes in from there.

The iPhone application I created uses this:

-(IBAction)pressButton:(id)sender {
    NSString *iHostname = [NSString stringWithFormat:@"xxx.xxx.xxx.xxx"];
    NSString *iPort = [NSString stringWithFormat:@"9100"];

    CFWriteStreamRef writeStream;
    static const CFOptionFlags kWriteNetworkEvents = kCFStreamEventEndEncountered |
    kCFStreamEventErrorOccurred |
    kCFStreamEventCanAcceptBytes |
    kCFStreamEventOpenCompleted |
    kCFStreamEventNone;
    CFStreamClientContext ctxt = {0,(void*)NULL,NULL,NULL,NULL};
    CFHostRef hostRef = CFHostCreateWithName(kCFAllocatorDefault,(CFStringRef)iHostname);

    CFStreamCreatePairWithSocketToCFHost(kCFAllocatorDefault, hostRef, [iPort intValue],
                                         NULL, &writeStream);

    CFWriteStreamSetClient(writeStream, kWriteNetworkEvents, WriteStreamClientCallBack, &ctxt);
    CFWriteStreamScheduleWithRunLoop(writeStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

So, I call a runloop method:

static void WriteStreamClientCallBack( CFWriteStreamRef stream, CFStreamEventType type, void *clientCallBackInfo ) {
    NSLog(@"%lu", type);
    switch (type)
    {
        case kCFStreamEventEndEncountered:
        {
            NSLog(@"Closing");
            CFWriteStreamClose(stream);
            break;
        }
        case kCFStreamEventErrorOccurred:
        {
            NSLog(@"Crap, error!");
            break;
        }
        case kCFStreamEventCanAcceptBytes:
        {
            NSLog(@"Stream can accept more bytes");
            NSString *reqStr = [NSString stringWithFormat: @"ConReq"];
            const UInt8 *rawstring = (const UInt8 *)[reqStr UTF8String];
            CFWriteStreamWrite(stream, rawstring, strlen((char *)rawstring));
        }
        case kCFStreamEventNone:
        {
            NSLog(@"Nothing is happening");
            break;
        }
        case kCFStreamEventOpenCompleted:
        {
            NSLog(@"Opened stream!");
            break;
        }
    }
}

Here comes the problem: when I press the button, it stays looped in there. Logging shows case kCFStreamEventCanAcceptBytes just keeps on getting called. Indeed, when I forcequit the program, the server has received a file with a lot of ConReq in it. What should I do about it, or what am I doing wrong?

PS. I got the code from here.

  • 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-23T08:18:34+00:00Added an answer on May 23, 2026 at 8:18 am

    The “can accept” event indicates that, if you have more data to send, you can send (some of) it without blocking. Your problem is you are not tracking how much data you have sent, how much data you have left to send, and whether the socket can currently accept data. Instead, every time there’s space to send more data, you send the exact same data every time. It’s not much data, so you should expect to quickly see a whole lot of “ready for more data” events.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.