|
From: | Richard Frith-Macdonald |
Subject: | Re: NSConnection help |
Date: | Fri, 16 May 2003 09:40:48 +0100 |
On Friday, May 16, 2003, at 08:53 am, michael.de-checchi@laposte.net wrote:
Hi, We are a group of programmers working on a GNU Project (Hégémonie), and are newbies in Objective C. We are trying to use a Client/Server system and have some questions : When a message is received by the server, we need to identify the client sending the message, we have thought about identifying the NSConnection used by the message for this (like we would have identified a client by the socket used in low-level net programming). Is it possible, and how ?
That's not really possible because the distributed objects system is designed to make messaging totally transparent, so within a method you can no more tell what client sent the message invoking the method than you can tell which function is calling another function. If you want to know who is calling a method, you need to have the caller pass that information as one of the method arguments.
eg. - (id) getValue: (id)sender { if ([validSenders member: sender] == nil) {[NSException raise: @"InvalidSenderException" format: @"sender not known"];
} // Do normal stuff here. return theResult; } and have the server implement some sort of registration method ...- (BOOL) registerSelf: (id)sender asClientNamed: (NSString*)name password: (NSString*)passwd
{ if ([self isValidName: name andPassword: passwd]) { [validSenders addObject: sender]; return YES; } return NO; // Login details bad }If what you want is some sort of access control, you can set up a connection delegate and use the -authenticateComponents:withData: method to check that the client process is providing specific authentication data. This will prevent methods being used by clients who don't provide the appropriate data. See nsconnection_client.m and nsconnection_server.m in base/Testing for an example (though it trivially encrypts all messages rather than providing/checking authentication data).
[Prev in Thread] | Current Thread | [Next in Thread] |