Reputation: 13
I am trying to make a simple TCP socket connection from an iPad.
I got a set of code up and running using the simulator and it works fine.
But when I run this code on the iPad it fails.
Heres the code...
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.1.10", 19997, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream open];
[outputStream open];
The code hangs on [inputStream open]; then I get the error:
The Operation Couldn't be completed. Operation timed out. Code 60.
Am I missing something simple here? iOS permissions or something? Why would it work on the Simulator? I am new to iOS development.
Thanks for your help!
Upvotes: 0
Views: 3573
Reputation: 4331
I tested your code on my iPhone and it works fine. The 'other end' of the connection might be a problem though.
You should test the same code with www.google.com port 80.
Also you could test it in another project or at another 'point' in your project. Maybe there is a problem with 'where you call the code'
You should also consider just using an existing framework for these connections instead of writing everything yourself.
I use Google Async Sockets for this.
Upvotes: 1