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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:41:28+00:00 2026-06-02T09:41:28+00:00

ViewController.h @interface ViewController : UIViewController{ CFSocketRef s; int connectFlag; } ViewController.m void receiveDataCilent(CFSocketRef cs,

  • 0

ViewController.h

@interface ViewController : UIViewController{
CFSocketRef s;
int connectFlag;
}

ViewController.m

void receiveDataCilent(CFSocketRef cs, 
                   CFSocketCallBackType type, 
                   CFDataRef address, 
                   const void *data, 
                   void *info)
{  

CFDataRef df = (CFDataRef) data;
int len = CFDataGetLength(df);
if(len <= 0) return;

CFRange range = CFRangeMake(0,len);
UInt8 buffer[len];
NSLog(@"Received %d bytes from socket %d\n", 
      len, CFSocketGetNative(cs));
CFDataGetBytes(df, range, buffer);
NSLog(@"Client received: %s\n", buffer); 
NSLog(@"As UInt8 coding: %@", df);
NSLog(@"len value: %d", len);


}

-(void) clientConnect:(int)sender;{



s = CFSocketCreate(NULL, PF_INET, 
                    SOCK_STREAM, IPPROTO_TCP, 
                    kCFSocketDataCallBack, 
                    receiveDataCilent, 
                    NULL);

struct sockaddr_in      sin; 
struct hostent          *host;

memset(&sin, 0, sizeof(sin));

host = gethostbyname("localhost");      

memcpy(&(sin.sin_addr), host->h_addr,host->h_length); 

sin.sin_family = AF_INET;
sin.sin_port = htons(6666);

CFDataRef address;
CFRunLoopSourceRef source;

address = CFDataCreate(NULL, (UInt8 *)&sin, sizeof(sin));
CFSocketConnectToAddress(s, address, 0);

CFRelease(address);

source = CFSocketCreateRunLoopSource(NULL, s, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), 
                   source, 
                   kCFRunLoopDefaultMode);
CFRelease(source); 
CFRunLoopRun(); 

}

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

if(connectFlag == 0 ){
[self clientConnect:1];
}

}

First I’m sorry for messing the concept of xcode programming and threading programming I’m very new to xcode and I need to finish my game project soon

This code is suppose to connect to server and waiting for message from server. I try and test it and it work fine. In view I have IBAction that can press and change view.

But after I implement it to my main project. It can run but I cannot press any button or do anything. After log it out. It seem it stuck around CFRunLoopRun(); I think it stuck in loop but why when I test it. it not stuck ?

In my project this code is run from another view not from ViewController like I just test.
I don’t know why it stuck in my project.

Any help would be appreciated.

  • 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-02T09:41:34+00:00Added an answer on June 2, 2026 at 9:41 am

    Don’t run the run loop yourself on the main thread. The main event loop will run it.

    Edit: I should say, “within the context of a GUI app”. In a command-line tool, you do need to run the run loop yourself.

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

Sidebar

Related Questions

view1.h #import view2.h @interface ViewController : UIViewController { int count; } @property (nonatomic, assign)
I'm developing an iOS 4 application. I have this ViewController: @interface BlogViewController : UIViewController
// ViewController.h @interface ViewController : UIViewController{ IBOutlet UIButton *btnname; IBOutlet UITextView *txtname; IBOutlet UILabel
I have a problem with this code: Header: @interface ViewController : UIViewController { IBOutlet
Here is my code: Header: #import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIImageView *imageView;
Why are people using @interface ViewController : UIViewController { @private UIButton* button_; } @private
In this code: #import <UIKit/UIKit.h> @interface ViewController : UIViewController { UILabel *labelsText; } @property(strong,
secondViewController.h : #import <UIKit/UIKit.h> @interface secondViewController : UIViewController @end viewController.m : #import ViewController.h #import
If I have a variable in my view controler viewcontroller.m @interface MemoryTestViewController : UIViewController
I have defined a property in my viewcontroller as follows @interface QuestionAnswerViewController : UIViewController

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.