IN GIST
Meanwhile, I will try to add more information if it helps. We are actually hosting a server built in .NET and we have 2 clients. One is Android and another is iOS. We are making service calls through chat messages and the problems occurs only when we have made around 4-5 calls and then kill the app in iPad or Android and then reopen it and then why it tries to join the session it gives the following error:
ER_ALLJOYN_JOINSESSION_REPLY_UNREACHABLE
QStatus status = self.busAttachment->JoinSession([sessionName UTF8String], sessionPort, listenerImpl, sessionId, ((ajn::SessionOpts)options.handle));
IN DETAILS
I am trying to make an app using ALLJOYN. Instead of using it as a chat sample I have tried to use it as an server which will give me response on basis of my request. I have used ALLJOYN sdks code to connect and disconnect.
Here I am posting the code which I have tried.
If I make a single request in one connection and disconnect it and try to connect again I can connect for 4 times consecutively and in the 5th time server is crashing (in my side the session id is becoming 0) but if I do multiple requests and disconnect it and try to make connection again the server is getting crashed. Please let me know if anyone has any idea how to stop the server crashing. Thank you in advance.
COONECTION CODE:
-(void)connect{
QStatus status = ER_OK;
self.busAttachment = [[AJNBusAttachment alloc] initWithApplicationName:kAppName allowRemoteMessages:YES];
// app.busAttachmentGlobal=self.busAttachment;
// create and register our interface
//
AJNInterfaceDescription* chatInterface = [self.busAttachment createInterfaceWithName:kInterfaceName];
// app.chatInterfaceGlobal=chatInterface;
status = [chatInterface addSignalWithName:@"Chat" inputSignature:@"s" argumentNames:[NSArray arrayWithObject:@"str"]];
if (status != ER_OK && status != ER_BUS_MEMBER_ALREADY_EXISTS) {
@throw [NSException exceptionWithName:@"BusObjectInitFailed" reason:@"Unable to add method to interface: cat" userInfo:nil];
}
else
{
}
[chatInterface activate];
// register signal handler
//
self.chatObjectSignalHandler = [[AJNCChatObjectSignalHandler alloc] init];
self.chatObjectSignalHandler.delegate=nil;
self.chatObjectSignalHandler.delegate = self;
[self.busAttachment registerSignalHandler:self.chatObjectSignalHandler]; //registering signal handler
// app.chatObjectSignalHandlerGlobal=self.chatObjectSignalHandler;
// create and register the chat bus object
//
self.chatObject = [[AJNCBusObject alloc] initWithBusAttachment:self.busAttachment onServicePath:kServicePath];
self.chatObject.delegate = self;
[self.busAttachment registerBusObject:self.chatObject]; //registering bus
// start the bus
//
status = [self.busAttachment start];
if (status != ER_OK) {
NSLog(@"ERROR: Failed to start bus. %@", [AJNStatus descriptionForStatusCode:status]);
}
else{
NSLog(@"bus started succesfully");
}
// register our view controller as the bus listener
//
[self.busAttachment registerBusListener:self];
//
// connect to the bus
//
status = [self.busAttachment connectWithArguments:@"null:"];
if (status != ER_OK) {
NSLog(@"ERROR: Failed to connect bus. %@", [AJNStatus descriptionForStatusCode:status]);
}
else{
NSLog(@"bus connected succesfully");
}
if (gMessageFlags == kAJNMessageFlagSessionless) {
// [self disconnect];
// [self connect];
NSLog(@"Adding match rule : [%@]", self.sessionlessSignalMatchRule);
status = [self.busAttachment addMatchRule:self.sessionlessSignalMatchRule];
if (status != ER_OK) {
// NSLog(@"ERROR: Unable to %@ match rule. @"remove" : @"add", [AJNStatus descriptionForStatusCode:status]);
NSLog(@"Error:unable to match rule");
}
}
else {
// get the type of session to create
//
serviceName = [NSString stringWithFormat:@"%@%@", kServiceName, @"chat"];
status=[self.busAttachment findAdvertisedName:serviceName];
if (status!=ER_OK) {
NSLog(@"didnot find");
} else {
NSLog(@"found the advesrtiser");
}
}
}
DISCONNECT:
-(void)disconnect:(LoginViewController *) ob {
[ob.busAttachment cancelAdvertisedName:serviceName withTransportMask:kAJNTransportMaskAny];
// disconnect from the bus
//
[ob.busAttachment disconnectWithArguments:@"null:"];
// unregister our listeners and the chat bus object
//
[ob.busAttachment unregisterBusListener:ob];
[ob.busAttachment unregisterSignalHandler:ob.chatObjectSignalHandler];
[ob.busAttachment unregisterBusObject:ob.chatObject];
// stop the bus and wait for the stop operation to complete
//
[ob.busAttachment stop];
[self.busAttachment waitUntilStopCompleted];
// dispose of everything
//
ob.chatObjectSignalHandler.delegate = nil;
ob.chatObjectSignalHandler = nil;
ob.chatObject.delegate = nil;
ob.chatObject = nil;
ob.busAttachment = nil;
}
Delegate method:
- (void)didFindAdvertisedName:(NSString *)name withTransportMask:(AJNTransportMask)transport namePrefix:(NSString *)namePrefix
{
NSString *conversationName = [NSString stringWithFormat:@"%@", [[name componentsSeparatedByString:@"."] lastObject]];
NSLog(@"Discovered chat conversation: \"%@\"\n", conversationName);
// [self.busAttachment enableConcurrentCallbacks];
/* Join the conversation */
AJNSessionOptions *sessionOptions = [[AJNSessionOptions alloc] initWithTrafficType:kAJNTrafficMessages supportsMultipoint:YES proximity:kAJNProximityAny transportMask:kAJNTransportMaskAny];
//*********After the above line the server is crashing *********
AJNSessionId sessionId = [self.busAttachment joinSessionWithName:name onPort:kServicePort withDelegate:self options:sessionOptions];
if (sessionId == 0) {
alert=[[UIAlertView alloc] initWithTitle:@"" message:@"Server not found.Please try after sometime. " delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
}
if (sessionId > 0 && self.sessionId == 0) {
self.sessionId = sessionId;
NSLog(@"Successfully joined session [%u].", sessionId);
// let our delegate know that we connected to the service
//
}
}
When the server is crashing my log shows these messages.
140.369 ****** ERROR ALLJOYN_OBJ JoinS-1 .../router/AllJoynObj.cc:2286 | SendAttachSession failed: ER_BUS_REPLY_IS_ERROR_MESSAGE
140.370 ****** ERROR ALLJOYN_OBJ JoinS-1 ...e/router/AllJoynObj.cc:937 | AttachSession to :xFEpNXdT.1 failed: ER_BUS_REPLY_IS_ERROR_MESSAGE