Registering Clients using DO
Registering Clients using DO
- Subject: Registering Clients using DO
- From: Kiran Kumar S <email@hidden>
- Date: Thu, 30 Apr 2009 11:17:22 +0530
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
I think my registering of client with server goes wrong , can anyone
suggest me what i am missing here.If any sample code that would be
great.
Server
-------
main() {
int newSocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in address;
memset(&address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons(PORT_NUMBER);int yes = 1;
setsockopt(newSocket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
bind(newSocket, (struct sockaddr *)&address, sizeof(address));
listen(newSocket, 128);
NSSocketPort *serverPort = [[NSSocketPort alloc]
initWithProtocolFamily:PF_INET socketType:SOCK_STREAM protocol:0
socket:newSocket];
connection = [[NSConnection alloc] initWithReceivePort:serverPort
sendPort:serverPort];
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
[connection setRootObject:[ServerObject sharedServerObject]];
[connection addRunLoop:runloop];
[runloop run];
}
@implementation ServerObject : NSObject
-(void)registerClient:(id<NetClientProto>)client {
[clients setObject:client forKey: @"C1"];
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];
}
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];
[port release];
serverObject = [connection rootProxy];
[serverObject performSelector:@selector(registerClient:)
withObject:self];
}@catch(NSException *exception){
[self destroyConnection];
}
return serverObject;
}
-(void)ping{
NSLog(@"server pinged");
}
Regards
SKiran
_______________________________________________
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