断开GCDAsyncSocket时出现异常

时间:2013-06-11 18:44:03

标签: iphone ios xcode sockets gcdasyncsocket

我刚开始使用GCDAsyncSocket连接到我的服务器。客户端和服务器之间的通信正常,但是当服务器(vb.net应用程序)断开连接时,我在客户端(Xcode iOS)中遇到以下异常:

  

*由于未捕获的异常'NSMallocException'而终止应用程序,原因:' - [NSConcreteMutableData appendBytes:length:]:无法为长度分配内存( 4294967295)”   * *第一次抛出调用堆栈:   (0x16f9012 0x151ee7e 0x16f8deb 0xf2d39e 0xf2cf76 0x2b74f 0x2bd5b 0x175764b 0x16c08fd 0x16c087a 0x16c06ac 0x16c04e7 0x17f855 0x17f926 0x17e2bf 0x182098 0x181ca5 0x1823ff 0x182370 0x7ed53 0x7e59d 0x7e4d0 0x16b9aa8 0x167cf3f 0x167c96f 0x169f734 0x169ef44 0x169ee1b 0x272d7e3 0x272d668 0x462ffc为0x2102 0x2035为0x1)   libc ++ abi.dylib:terminate调用抛出异常

我的GCDAsyncSocket连接块如下所示:

    // Block: Connection established
    [NetworkController sharedInstance].connectionOpenedBlock = ^(NetworkController* connection){
        NSLog(@"Connection established.");
    };

    // Block: Connection fail
    [NetworkController sharedInstance].connectionFailedBlock = ^(NetworkController* connection) {
        NSLog(@"Connection failed.");
    };

    // Block: Connection closed
    [NetworkController sharedInstance].connectionClosedBlock = ^(NetworkController* connection) {
        NSLog(@"Connection closed");
    };

    // Block: Message received
    [NetworkController sharedInstance].messageReceivedBlock = ^(NetworkController* connection, NSString* message){
        [self processMessage:message];
    };


        [[NetworkController sharedInstance] connect:tHostname];

有人能给我一个提示吗?

提前谢谢!

问候 塞巴斯蒂安

2 个答案:

答案 0 :(得分:0)

好吧,我了解到我的问题根本没有帮助,对不起家伙:)

对于解释调试器注释有困难的每个人,请阅读本文:Ray Wenderlich: My App Crashed, Now What?,它帮助我找到导致错误的代码行。

答案 1 :(得分:0)

在将您的网络与聊天服务器连接之前,请添加以下行:[[NetworkController sharedInstance] disconnect]; 例如:

[[NetworkController sharedInstance] disconnect];
[[NetworkMessageParser shared] connectWithChatServer];