1

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

* 由于未捕获的异常'NSMallocException'而终止应用程序,原因:'-[NSConcreteMutableData appendBytes:length:]: unable to allocate memory for length (4294967295)' * * First throw call stack: (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:终止调用抛出异常

我的 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];

任何人都可以给我一个提示这个问题吗?

先感谢您!

问候塞巴斯蒂安

4

1 回答 1

0

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

[[NetworkController sharedInstance] disconnect];
[[NetworkMessageParser shared] connectWithChatServer];
于 2017-03-06T08:39:58.680 回答