我想從iPad做一個簡單的TCP套接字連接。iPad的TCP連接套接字超時(代碼60)
我得到了一套代碼並運行使用模擬器,它工作正常。
但是,當我在iPad上運行此代碼失敗。
赫雷什代碼...
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];
代碼掛起[開放的inputStream]。那麼我得到的錯誤:
The Operation Couldn't be completed. Operation timed out. Code 60.
我在這裏丟失的東西很簡單嗎? iOS權限什麼的?它爲什麼會在模擬器上工作?我是iOS開發新手。
感謝您的幫助!
在打開流之前,您是否嘗試將它們添加到運行循環中? [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server 我從我的手機發帖很抱歉沒有正確格式化 – badger0053 2013-04-08 19:01:42