Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket is disconnected immediately after making connection by using GCDAsyncSocket library in iPhone application

I want to read and write data from OBD2 Wifi enabled Adapter which is used to read car data and fault codes. For that ,I'm using GGCDAsyncSocket Library for socket connection.

You can download CocoaAsyncSocket Library source code

But it maintains connection hardly for 10 seconds and sometimes 40-50 seconds and then terminated.

And the logs shows :

Socket disconnected : Error Domain=NSPOSIXErrorDomain Code=57 "The operation couldn’t be completed. Socket is not connected" UserInfo=0x14cd50 {}

Any help or idea would be appreciated !

Thanks in advance !

Please look at below code :

- (void)connectObdKeyHost:(NSString*)strHost port:(NSString *)strPort {
        [gcdAsyncSocket connectToHost:strHost onPort:portNo withTimeout:30 error:&error];
}

// GCDAsyncSocket Delegate Methods
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port {
   NSLog(@"Socket connected : ");
}

- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
{
    NSLog(@"Socket disconnected : %@",err);
}
like image 672
NSS Avatar asked Dec 06 '13 13:12

NSS


1 Answers

I tried with below method :

    [gcdAsyncSocket connectToHost:strHost onPort:portNo error:&error];

and now it's working.

like image 150
NSS Avatar answered Oct 04 '22 08:10

NSS