0

Can anyone tell me why the code connects

- (IBAction)connectBtn:(id)sender {

  socket = [[AsyncSocket alloc] initWithDelegate: self];
  [socket connectToHost: @"127.0.0.1" onPort: 4321 error: nil];

}

and the code below crashes on connecttohost

- (void)viewDidLoad
{
 socket = [[AsyncSocket alloc] initWithDelegate: self];
  [super viewDidLoad];

}
- (IBAction)connectBtn:(id)sender {

[socket connectToHost: @"127.0.0.1" onPort: 4321 error: nil];

 }

the socket is defined in view controller.h file

 @interface ViewController : UIViewController{
 AsyncSocket *socket;

 }
  • 1
    Can you post the error you get? Is socket weakly retained if so it is probably getting deallocated. – Ben Avery Oct 13 '13 at 21:34
  • Also (actually doesn't know if there's something related to the error), but always call `[super viewDidLoad]` as the first line inside the method – Lucas Eduardo Oct 13 '13 at 22:21
  • The error is below, can you explain weakly retained I tried – user1858353 Oct 14 '13 at 00:20
  • 2013-10-13 20:09:53.304 test005[8629:11303] -[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7147f50 2013-10-13 20:09:53.306 test005[8629:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x7147f50' *** First throw call stack: libc++abi.dylib: terminate called throwing an exception (lldb) – user1858353 Oct 14 '13 at 00:20

0 Answers0