0

I have been trying get my head around this for last few weeks now.

All i want to do is be able to send a string created on the iphone/ipad and send that to a specific ip address and port number. That ip address will then return 'something' and i want to display a message back on the iphone/ipad.

I have tried using sample projects i came across , but can never get the damn thing to work. I fear i am making this alot harder than it needs to be - but some help would really be appreciated.

Thanks

Sam

Sam Parrish
  • 1,377
  • 1
  • 11
  • 17

2 Answers2

0

Do you want to send it to a device in the same network? I have modified GKRocket to send a string and then display it in a UIAlert in the second device: Here's my modification:

-(void) sendPacket:(PacketType)packetType
{

    NSString * string = [[NSString alloc] initWithFormat:@"Message"];
    NSData *packet = [string dataUsingEncoding:NSUTF8StringEncoding];
    [manager sendPacket:packet ofType:packetType];
    [string release];
}

- (void) session:(SessionManager *)session didReceivePacket:(NSData*)data ofType:(PacketType)packetType
{
    UIAlertView * alert;
    NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    switch (packetType) {
        case PacketTypeString:
            alert = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@", str] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        default:
            break;
    }
}
Basel
  • 2,368
  • 1
  • 16
  • 21
  • no, the devices wont communicate with each other, only with the server. i want the device to send a string to the server, the server will pick up that request, deal with it, and send a message back, the device will receive the message back and display it. – Sam Parrish Mar 14 '11 at 10:02
  • @Basel Abdelaziz Is it possible to send the packets/message string to any specific iPhone using the MAC Address of iPhone other than APNS? – Ajay Sharma Oct 05 '12 at 05:36
0

user NSURLConnection class, you can find referenece at http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request.

NSURLConnection’s delegate methods allow an object to receive informational callbacks about the asynchronous load of a URL request. Other delegate methods provide facilities that allow the delegate to customize the process of performing an asynchronous URL load.

Hanuman
  • 642
  • 5
  • 19