You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Sewon <ri...@gmail.com> on 2011/07/08 08:16:45 UTC

reconnecting cocoa client

I'm using thrift 0.2 version with below

server: java
client: cocoa touch (iphone)

All connections and transporting data are successful. But I don't know how to clear socket or reconnecting on cocoa
It means that when the application resign active, I want to close the connection and then reconnect to the server when becoming active. 

simply, I tested like below

-(void)connect:(NSString*)ip serverPort:(NSUInteger)portNum {
    
    transport = [[TSocketClient alloc] initWithHostname:ip 
                                                   port:portNum];
    protocol = [[TBinaryProtocol alloc] initWithTransport:transport
                                               strictRead:YES 
                                              strictWrite:YES];
    service = [[serverDBIOServiceClient alloc] initWithProtocol:protocol];
}

-(void)reconnect {
    [transport initWithHostname:serverIP port:serverPort];
    [protocol initWithTransport:transport  strictRead:YES strictWrite:YES];
    service = [service initWithProtocol:protocol];
}

-(void)disconnect {
    [service release];
    [protocol release];
    [transport release];
    service = nil;
}

Is it right? it almost has been fine on test. but sometimes crashed
Please show me good examples.

thanks in advance
Sewon Na