大家午安
小弟刚进入ios的开发世界,第一次使用第三方库gcdasyncsocket来写client
照了作者github实作init 成功了 也连到server, 此时server会送字串出来
我client去收却说socket已断了
可我用netstat -nap tcp看连线还建立著
是我少了什么步骤吗?
-(void) didInitNetwork{
myAsyncSocket =[[GCDAsyncSocket alloc]
initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *nsErr=nil;
[myAsyncSocket connectToHost:@"192.168.1.102" onPort:31010 error:&nsErr];
}
//receive button
- (IBAction)receive_data_btn:(id)sender {
if([myAsyncSocket isConnected]==YES)
{
[myAsyncSocket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:1];
}
}
//callback
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{
NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length] - 2)];
NSString *msg = [[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding];
NSLog(msg);
self.status_label.text=msg;
}