Re: Can server send message to client through NSConnection
Re: Can server send message to client through NSConnection
- Subject: Re: Can server send message to client through NSConnection
- From: Ondra Cada <email@hidden>
- Date: Wed, 28 Nov 2001 18:41:38 +0100
feil,
>
>>>>> email@hidden (f) wrote at Wed, 28 Nov 2001 10:28:07 -0700:
f> For NSConnection in documentation, it seems only client application can
f> send message(defined in protocol for proxy) to server application
f> through proxy it get for server application. But my situation is the
f> server application will obtain some data from time to time, and I hope
f> server application will send the data to client application as soon as
f> it get these data instead of client application keep asking about the
f> data(sometimes server may have, sometimes may not). That is, can server
f> send message to client when the data is ready?
When the client connects to server, it would send him an object which is to
be informed of news, like this:
@protocol ServerProtocol
...
-(void)setObserver:anObject;
...
@end
Server would just store the object the very simple way
-(void)setObserver:anObject {
observer=[anObject retain]; // in practice, you would probably save it to
an array or so, since there are more clients, ie. more observers
}
and then use it:
...
if (something_happened) [observer tellTheClient];
...
That's all: the beauty of DO. The object which client sent as an argument of
setObserver: would get the tellTheClient message.
(Well, to do that quite properly you should observe timeouts, and set nil to
observer if the appropriate client died.)
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc