Reputation: 1679
i red a tutorial about iOS socket programming. Networking Tutorial for iOS. As described I started the sever using a python script. I connected some clients via telnet and everything worked fine. Then i wrote the code or the iOS Application and there is something wrong. When i run the App in the Simulator its works great, but on my Device, nothing works.
i have the following iOS-Code
- (void)initNetworkCommunication
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)(@"127.0.0.1"), 80, &readStream, &writeStream);
inputStream = (__bridge_transfer NSInputStream *)readStream;
outputStream = (__bridge_transfer NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
So what is wrong here? Can anybody help me please?
Upvotes: 0
Views: 1127
Reputation: 1289
My guess is you are trying to connect to localhost (127.0.0.1) from a device that is not running locally like your simulator is. You need to try and connect to the actual IP of the server on your local network if you want it to work from your iOS device. The current address will only work if the code is run on the same machine running the server, hence why the simulator works and your device does not.
Upvotes: 2