views:

18

answers:

0

So I've been teaching myself objective-c the past few months, building an iPhone app for my company. I started as (and still am) a complete novice, but until now I have had no problems easily finding answers to all my questions at various locations online.

For the final, and most important, piece of my app, I need to send a simple string to an address/port via UDP when a button is pressed. The string, address, and port are all variables pulled from an object passed to my view controller.

I have been digging around for two days looking at solutions and reading examples, but everything seriously reads like Greek to me. I'm not sure what major hunk of knowledge I seem to have missed out on, but I'm at a total loss. I learned about cocoaasyncsocket, and how "simple" it is, and it sounded perfect for what I need, but I just can't seem to wrap my mind around it. I'm really hoping someone here can help break it down for me into the simplest terms...

Here is a snippet of the code I've been trying, but with no luck. This code is from my viewController, with AsyncUdpSocket.h imported:

-(IBAction)udpButtonTwoPressed:(id)sender {

NSData *myData;
myData = [[NSData alloc] initWithData:([selectedObject valueForKey:@"udpCommandTwo"])];

AsyncUdpSocket *mySocket;
mySocket = [[AsyncUdpSocket alloc] initWithDelegate:self ];

NSError *error = nil;
if (!([mySocket connectToHost:([selectedObject valueForKey:@"serverIPAddress"]) onPort:([[selectedObject valueForKey:@"serverPort"] intValue]) error:&error])) {
    NSLog(@"Can't Connect Cause: %@", error);
    abort();
}

[mySocket close];

[mySocket release];
[myData release];

}

I'm really hoping someone can maybe point me in the right direction as to what I'm doing wrong here?

Thank you so much in advance!!