Re: Registering Clients using DO
Re: Registering Clients using DO
- Subject: Re: Registering Clients using DO
- From: Ken Thomases <email@hidden>
- Date: Thu, 30 Apr 2009 01:33:00 -0500
On Apr 30, 2009, at 12:47 AM, Kiran Kumar S wrote:
I am developing a client/server application using DO. In server an
object is vended to be accessible by clients.In the client side i am
accessing vended object and get required info from server.Every
thing works fine. Until now my client queries server and server
replies to that. But on serverside if any updates goes, i had to
inform client.so i thought of registering the client and ping the
client for updates.So in Client side i get vended object and
registered it to server.When my server pings the client its giving
error *** NSDistantObject initWithCoder: 0x1 not given away for conn
0xf8937f0
Can you break on this error? On what line of code is it happening?
What's the backtrace?
@implementation ServerObject : NSObject
-(void)registerClient:(id<NetClientProto>)client {
You didn't show the NetClientProto protocol, although I'm guessing
it's pretty simple.
[clients setObject:client forKey: @"C1"];
All clients are recorded under the same key?
if(![timer isValid])
timer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self
selector:@selector(pingClients) userInfo:nil repeats:YES] retain];
}
-(void)pingClients {
[[clients objectForKey:[[clients allKeys] lastObject]] ping];
This is a strange construct. I assume that 'clients' is a
dictionary. Have you tried just enumerating the dictionary objects
and invoking -ping on each?
for (id<NetClientProto> client in [clients objectEnumerator])
[client ping];
}
Client
-------
-(id)getServer{
@try{
NSSocketPort *port = [[NSSocketPort alloc]
initRemoteWithTCPPort:PORT_NUMBER host:host];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:nil sendPort:port];
[connection setDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleConnectionDied:)
name:NSConnectionDidDieNotification object:serverConnection];
I assume you meant "connection" instead of "serverConnection" here?
[port release];
serverObject = [connection rootProxy];
[serverObject performSelector:@selector(registerClient:)
withObject:self];
Why are you using -performSelector:... here? What's the declaration
of 'serverObject'?
Best practice is to have a protocol for each side of the connection,
defined in a header that is shared between the code bases. Then you
don't have to relying on things like -performSelector:... You could
just invoke -registerClient: directly.
Such a protocol is also where you'd specify bycopy, oneway, and
similar specifiers.
Furthermore, you should use -[NSDistantObject setProtocolForProxy:]
for efficiency, and probably NSProtocolChecker (on the server side)
for security.
}@catch(NSException *exception){
Have you considered logging here?
[self destroyConnection];
}
return serverObject;
}
-(void)ping{
NSLog(@"server pinged");
}
Is your client then running its run loop, waiting to be pinged? Is it
the same thread and run loop where -getServer was called?
Regards,
Ken
_______________________________________________
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