我有以Objective-C編寫的將數據寫入套接字的代碼。服務器在Ubuntu上運行node.js:在iOS中保持套接字連接有效
NSString *url = @"anIPAddress";
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)url, 9000, &readStream, &writeStream);
self.inputStream = (NSInputStream *)readStream;
self.outputStream = (NSOutputStream *)writeStream;
[self.inputStream setDelegate:self];
[self.outputStream setDelegate:self];
[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.inputStream open];
[self.outputStream open];
我可以連接到服務器併發送信息。不過,我注意到幾分鐘後連接超時(我想5分鐘左右?)。我怎樣才能保持這種聯繫?我知道有一個斷開連接,因爲如果我連接到終端下的服務器,同樣的事情發生,我必須保持連接活着。我想象我的代碼中正在發生同樣的事情。謝謝你的幫助!
對於有效的Objective-C代碼,請參考[下面的答案](http://stackoverflow.com/a/25725181)... – Despotovic 2016-02-03 23:08:15