0

This code carry on some communication to server on app device. It worked fine until clients upgrade their iOS to version 9.

clientSocket = [[AsyncSocket alloc] initWithDelegate:self];

@try
{

    NSString *msg = [NSString stringWithFormat:@"ios:%@",encodeNum];
    if (!clientSocket.isConnected) {

        [clientSocket connectToHost:@"my.server.com" onPort:7009 error:nil];

    }

    NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
    [clientSocket writeData:data withTimeout:-1 tag:0];
}
@catch (NSException *exception)
{
    NSLog(@"exception: %@", exception);
}

In iOS 9, it throw following error:

 Attempting to connect while connected or accepting connections. Disconnect first.
irmorteza
  • 1,576
  • 3
  • 19
  • 32

1 Answers1

0

I'm getting the same issue. It seems clientSocket.isConnectedcan be false while it is still connecting. You need to listen to the delegate didConnectToHostto know when it has been connected.

Daniel Ryan
  • 6,976
  • 5
  • 45
  • 62