NSDistantObject exception when server trying to access registered clients using DO
NSDistantObject exception when server trying to access registered clients using DO
- Subject: NSDistantObject exception when server trying to access registered clients using DO
- From: Kiran Kumar S <email@hidden>
- Date: Wed, 6 May 2009 17:15:00 +0530
I am developing a client/server application using distributed objects.
I developed server and in that i vended an object to be accessible by
clients.In the client side i am getting the vended object, and getting
required info from server.Every thing works fine. Until now my client
ask server for his queries and server replies to that. But on the
serverside if any updates goes, i had to inform client.so i thought of
registering the client and ping the client for the updates.In the
Client side i am getting vended object and registering the client.When
my server pings the client giving the following exception.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2009-05-05 12:12:29.023 Project X[5278:10b] *** NSDistantObject
initWithCoder: 0x1 not given away for conn 0xf9f21e0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any one please help me out in this its really annoying
Server
---------
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
if ([NSHost respondsToSelector:@selector(_fixNSHostLeak)])
[NSHost _fixNSHostLeak];
if ([NSSocketPort respondsToSelector:
@selector(_fixNSSocketPortLeak)])
[NSSocketPort _fixNSSocketPortLeak];
NSSocketPort *receivePort = [[NSSocketPort alloc]
initWithTCPPort:PORT_NUMBER];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:receivePort sendPort:nil];
[receivePort release];
[connection enableMultipleThreads];
[connection setRootObject:[ServerObject sharedServerObject]];
[connection addRunLoop:runloop];
[connection setDelegate:self];
[receivePort release];
[runloop run];
------------------------------------------------------
--------------------------------------------------------------------- ------------------------- --------------------------------------------
if the socket is created as above , there is no exception when i am
trying to ping registered clients.But the problem with above is ,some
times socket is not allocated, so i thought of creating socket in the
following way
------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------
int newSocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in serverAddress;
memset(&serverAddress, 0, sizeof(serverAddress));
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(PORT_NUMBER);
//resusing the Socket
int yes = 1;
setsockopt(newSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
bind(newSocket, (struct sockaddr *)&serverAddress,
sizeof(serverAddress);
listen(newSocket, 128);
NSSocketPort *serverPort = [[NSSocketPort alloc]
initWithProtocolFamily:PF_INET socketType:SOCK_STREAM protocol:0
socket:newSocket];
serverConnection = [NSConnection connectionWithReceivePort:serverPort
sendPort:serverPort];
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
[serverConnection enableMultipleThreads];
[serverConnection setRootObject:[ServerObject sharedServerObject]];
[serverConnection addRunLoop:runloop];
[serverConnection setDelegate:self];
[runloop run];
[serverConnection release];
----------------------------------------------------------------------
Beacuse of above creation of scoket i am getting above exception
----------------------------------------------------------------------------
@protocol DServerProto
-(void)registerClient:(id)client withName:(NSString *)name;
-(void)exportProject:(NSDictionary *)projectDictionary;
@end
@implementation ServerObject
-(void)registerClient:(id)client withName:(NSString *)name {
[clients setObject:client forKey:name];
[client setProtocolForProxy:@protocol(DClientProto)];
if(![timer isValid]) {
timer = [[NSTimer scheduledTimerWithTimeInterval:5 target:self
selector:@selector(pingClients:) userInfo:nil repeats:YES] retain];
}
}
-(void)pingClients:(NSTimer *)pingTimer {
NSArray *clientKeys = [clients allKeys];
for(id key in clientKeys) {
@try {
[[clients objectForKey:key] ping];
} @catch (NSException *exception) {
[clients removeObjectForKey:key];
}
}
if(![[clients allKeys] count] && [timer isValid]) {
[timer invalidate];
[timer release];
timer = nil;
}
}
@end
Client
--------
NSSocketPort *port = [[NSSocketPort alloc]
initRemoteWithTCPPort:PORT_NUMBER host:host];
NSConnection *serverConnection = [NSConnection
connectionWithReceivePort:nil sendPort:port];
[port release];
[serverConnection setDelegate:self];
[serverConnection setRequestTimeout:5.0f];
[serverConnection setReplyTimeout:5.0f];
proxy = [[serverConnection rootProxy] retain];
[proxy setProtocolForProxy:@protocol(DServerProto)];
[proxy registerClient:monitor withName:self];
exception i am getting
------------------------------
2009-05-05 12:12:29.023 Project X[5278:10b] *** NSDistantObject
initWithCoder: 0x1 not given away for conn 0xf9f21e0
2009-05-05 12:12:29.024 Project X[5278:10b] NSExceptionHandler has
recorded the following exception:
NSInternalInconsistencyException -- *** -[NSConcretePortCoder
decodeInvocation]: no local target
Stack trace: 0xb6119a 0x94372e3b 0x95d8aeeb 0x95d8af2a
0x90e847bc 0x90e8425d 0x90e8074c 0x90e8386e 0x90e8358d
0x90e830be 0x90fc4395 0x90fc37ae 0x95d1a87c 0x95d1bf65
0x95d115f5 0x95d11cd8 0x910e9480 0x910e9299 0x910e910d
0x96bff3ed 0x96bfeca0 0x96bf7cdb 0x38f926 0x96bc4f14 0x37735
0x2cb6 0x1
An Project X exception of type NSInternalInconsistencyException occured.
*** -[NSConcretePortCoder decodeInvocation]: no local target
Stack trace:
1 +[NSException raise:format:arguments:] (in CoreFoundation) + 155
2 +[NSException raise:format:] (in CoreFoundation) + 58
3 -[NSConcretePortCoder decodeInvocation] (in Foundation) + 1068
4 -[NSConcretePortCoder decodeRetainedObject] (in Foundation) +
909
5 _NSWalkData2 (in Foundation) + 1724
6 -[NSConnection handleRequest:sequence:] (in Foundation) + 78
7 -[NSConnection handlePortCoder:] (in Foundation) + 1149
8 -[NSConcretePortCoder dispatch] (in Foundation) + 142
9 -[NSSocketPort _handleMessage:from:socket:] (in Foundation) +
821
10 __NSFireSocketData (in Foundation) + 734
11 __CFSocketDoCallback (in CoreFoundation) + 476
12 __CFSocketPerformV0 (in CoreFoundation) + 133
13 CFRunLoopRunSpecific (in CoreFoundation) + 3141
14 CFRunLoopRunInMode (in CoreFoundation) + 88
15 RunCurrentEventLoopInMode (in HIToolbox) + 283
16 ReceiveNextEventCommon (in HIToolbox) + 374
17 BlockUntilNextEventMatchingListInMode (in HIToolbox) + 106
18 _DPSNextEvent (in AppKit) + 657
19 -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit) + 128
20 -[NSApplication run] (in AppKit) + 795
21 -[MainApp run] (in Project X) (MainApp.m:506)
22 NSApplicationMain (in AppKit) + 574
23 main (in Project X) (main.m:28)
2009-05-05 12:12:31.725 Project X[5278:10b] *** -[NSConcretePortCoder
decodeInvocation]: no local target
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden