First Controller's code:
optionscontroller = [[OptionsViewController alloc] init ];
[optionscontroller setupSocket];
Second controller's code:
- (void)setupSocket
{
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
if (![udpSocket bindToPort:0 error:&error])
{
// [self logError:FORMAT(@"Error binding: %@", error)];
return;
}
if (![udpSocket beginReceiving:&error])
{
// [self logError:FORMAT(@"Error receiving: %@", error)];
return;
}
isRunning = YES;
NSLog(@"Udp Echo server started on port %hu", [udpSocket localPort]); }
One of actions:
- (IBAction)testbutton:(id)sender {
NSString *host = @"192.168.1.255";
if ([host length] == 0)
{
NSLog(@"Address required");
return;
}
NSString *msg = @"hi";
if ([msg length] == 0)
{
//[self logError:@"Message required"];
return;
}
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
[udpSocket enableBroadcast:YES error:nil ];
[udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:0];
tag++;
}
When i call "setupSocket" from first controller it starts, but when i go to OptionsViewController and click the button - nothing happens, it's connoted right and it works, when i call "setupSocket" from second controller's "view did load function" everything works okay, why???
So if initialize some methods not from target view controller this methods doesn't work. i can't understand how it may happen?