3

This is a weird one. I'm using GCDAsyncSocket and when I'm using 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 couldn’t be completed. Socket is not connected"

What is odd, I cannot predict when this will happen. Also when I check to see isConnected, that 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 fired with no issues and correct address and port returned, but when I try the above code to writeData to socket, I get the above error.

Any ideas why this would be happening randomly.

Mavro
  • 571
  • 8
  • 19
  • 4
    So it looks like it's an issue with the Simulator -- not 100% sure, yet. But, after a couple tests, if you leave the simulator open and then switch networks the issue happens. Solution, restarting simulator if you switch networks (home vs work) seems to fix the issue. – Mavro Jan 08 '15 at 18:56
  • This was driving me crazy. Your fix works for me too. Thank you! – mbeaty Mar 31 '15 at 06:11

0 Answers0