IOS GCDAsyncSocket error: Domain = NSPOSIXErrorDomain Code = 57

This is strange. I am using GCDAsyncSocket and when I use the iOS simulator sometimes I can connect and send, no problem, but sometimes when I try to connect and send something (writeData) I get the following error:

didDisconnect Error Domain = NSPOSIXErrorDomain Code = 57 "The operation could not be completed. The socket is not connected."

What's strange is that I can't predict when this will happen. Also when I check if there is isConnected this returns true.

Here is the code (SWIFT):

    var sendBytes:[Byte] = [0x0, 0x1, 0x2, 0x3] 
    var msgData = NSData(bytes: sendBytes, length: sendBytes.count)
    socket.writeData(msgData, withTimeout: -1.0, tag: 0)
    socket.readDataWithTimeout(-1.0, tag: 0)

      

The socket (didConnectToHost) callback fires without issue and the correct address and port, but when I try to execute the above code to write Data to the socket I get the above error.

Any ideas why this is happening randomly.

+3


source to share





All Articles