Modifierade koden från denhär guiden http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server och fick det att funka utmärkt.
Dock skulle jag gärna skriva om Serverdelen från Python till Objective-C. Dvs att kunna kommunicera med det här:
#import "aSocket.h"
@implementation aSocket
@synthesize inputStream, outputStream;
- (void)initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 1111, &readStream, &writeStream);
inputStream = (NSInputStream *)CFBridgingRelease(readStream);
outputStream = (NSOutputStream *)CFBridgingRelease(writeStream);
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
- (void) sendAction:(NSString*)input cellNumber:(NSString*)cellNumber {
NSString *response = [NSString stringWithFormat:@"Action:%@:%@", input, cellNumber];
NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
}
@end