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

1

7

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);
}
Bluh answered 6/12, 2013 at 13:2 Comment(1)
B
2

I tried with below method :

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

and now it's working.

Bluh answered 9/12, 2013 at 8:32 Comment(1)
I tried that and it still seems to be dropping on the host side, almost instantly (usually 2ms after it accepts). Weirdly, the client doesn't seem to be aware of the socket dropping out. Also, the error I get is null. Any ideas?Faintheart

© 2022 - 2024 — McMap. All rights reserved.