iOS上的Asyncsocket停留在代表处

时间:2014-02-22 21:27:24

标签: ios objective-c asyncsocket

我是目标C的新手,特别是iOS,但我花了最后一天来学习它。

我一直在尝试创建一个从套接字读取数据的简单应用。 我知道Asyncsocket是最好的解决方案并且已经开始使用它了,但是我遇到了一个问题..它通过所有代理(连接到主机,读取数据,断开连接)但随后它漂移并卡在某处。

继承人代码:

- (void) connect:(NSString *)ip PORT:(NSInteger)port
{
    //open asyncsoket
    connectSocket  = [[AsyncSocket alloc] initWithDelegate:self];
    [connectSocket setDelegate:self];

    // open connection
    NSError *error = nil;
    if (![connectSocket connectToHost:ip onPort:port error:&error]) {
        NSLog(@"Error starting client: %@", error);
        return;
    }
}




- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port{
    // if connection was succeful read from socket
    NSLog(@"connected to server");
    [sock readDataWithTimeout:-1.0 tag:0];



}


- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{

    //if did read data
    [connectSocket readDataWithTimeout:-1 tag:0];
    to_pass = data;
    [sock disconnect];

}


- (void)onSocketDidDisconnect:(AsyncSocket *)sock{
    // nothing to do

}

- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err{
    //nothing to do
}

如果我遵循断点,我似乎会经历所有需要的东西,但随后转到汇编代码并停在这里:

libsystem_kernel.dylib`mach_msg_trap:
0x2178f70:  movl   $4294967265, %eax
0x2178f75:  calll  0x217f4bc                 ; _sysenter_trap
0x2178f7a:  ret    ----> right here 
0x2178f7b:  nop    

0 个答案:

没有答案