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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:52:40+00:00 2026-05-22T12:52:40+00:00

i created a network Application to transfer text message between two devices through WiFi

  • 0

i created a network Application to transfer text message between two devices through WiFi network.when i select a device to pair there is a delegate called “TCPServerAcceptCallBack” will trigger in receiver side and it will setup the input and output streams.
but it will take milliseconds to do the setup of streams.whenever i am sending a data from my device there is checking of [_outStream hasSpaceAvailable].i mentioned that instream and outstream setup in receiver side will take milliseconds .so first time the condition will false.i used while loop to stop doing send method before setup is done.but there is a problem that when execution in while loop there is a chance to connection lose in receiver side and also not confident with while loop.
next i created a sleep of 3 millisecond ,it working fine but there is chance of occur error when network is very slow.
i am planning to trigger a delegate from receiver side to sender device at the time of instream and outstream setup is done.so please tell me how can do it (or) provide me any other good way to solve this problem…

My Code…receiver side
case NSStreamEventHasBytesAvailable:
{
if (stream == _inStream) {
// read it in
unsigned int len = 0;

//here the length is assigning..i can send text files only after this below statement is executed.but it will take few minitus.
len = [_inStream read:buf maxLength:buffSize];
buf[len] = ‘\0’;
if(!len) {
if ([stream streamStatus] != NSStreamStatusAtEnd)
NSLog(@”Failed reading data from peer”);
} else {
NSString *message = [NSString stringWithUTF8String:(char *)buf];

                //Display image from app bundle
                NSString *path=[[NSBundle mainBundle] pathForResource:message ofType:@"png"];   
                if(path !=nil)
                {
                [imageView setImage:[UIImage imageWithContentsOfFile:path]]; 
                }
                else
                {
                    UIImage *image = [UIImage imageNamed:@"no_image.png"];
                    [imageView setImage:image];
                }
                // here you do whatever you need with your received NSString *message
                [txtUserInput setText:message];

            }

        }
        break;

Sender part..


[- (void) sendText:(NSString *)string {
const uint8_t *message = (const uint8_t *)[string UTF8String];
//waiting up to outStream hasSpaceAvailable
while (![_outStream hasSpaceAvailable]) {
continue;
}
//once outStream hasSpaceAvailable it will send datas.
if (_outStream && [_outStream hasSpaceAvailable])
if([_outStream write:message maxLength:strlen((char *)message)] == -1)
NSLog(@”Failed sending data to peer”);
}
@end

  • 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-22T12:52:41+00:00Added an answer on May 22, 2026 at 12:52 pm

    Don’t use a while loop,that’s just wasting CPU cycles. Do it in the callback.

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

Sidebar

Related Questions

I created a simple .NET windows application in Visual Studio 2005 and on just
I created a Rails application normally. Then created the scaffold for an event class.
I created the setup project for the application and I can see that the
Is there a simple way to create a low priority transfer of a file?
I'm working on a social network web application, and I got a situation where
I created a Virtual Application in IIS 7 to host my app so I
I created a desktop application using VS 2008. When I run it locally, all
we are having latency issues in one of our network application. Most of the
I have this web application that i have created using Wicket, Guice and JPA.
My ASP.NET MVC 2 application runs under built-in local NETWORK SERVICE account. I want

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.