要点
同时,如果有帮助,我会尝试添加更多信息。我们实际上正在托管一个内置于 .NET 的服务器,并且我们有 2 个客户端。一个是Android,另一个是iOS。我们正在通过聊天消息进行服务调用,并且仅当我们进行了大约 4-5 次调用然后在 iPad 或 Android 中终止该应用程序然后重新打开它,然后为什么它尝试加入会话时才会出现问题,它会给出以下错误:
ER_ALLJOYN_JOINSESSION_REPLY_UNREACHABLE
QStatus 状态 = self.busAttachment->JoinSession([sessionName UTF8String], sessionPort, listenerImpl, sessionId, ((ajn::SessionOpts )options.handle));
详细信息
我正在尝试使用ALLJOYN制作应用程序。我没有将它用作聊天示例,而是尝试将其用作服务器,它将根据我的请求给我响应。我使用ALLJOYN sdks 代码进行连接和断开连接。
在这里,我发布了我尝试过的代码。
如果我在一个连接中发出单个请求并断开它并尝试再次连接,我可以连续连接 4 次,并且在第 5 次服务器崩溃(在我这边,会话 ID 变为 0)但是如果我执行多个请求并且断开它并尝试再次连接服务器正在崩溃。如果有人知道如何阻止服务器崩溃,请告诉我。先感谢您。
连接代码:
-(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");
}
}
}
断开:
-(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;
}
委托方式:
- (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
//
}
}
当服务器崩溃时,我的日志会显示这些消息。
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