Re: Client / Server Application
Re: Client / Server Application
- Subject: Re: Client / Server Application
- From: Sam Goldman <email@hidden>
- Date: Tue, 16 Oct 2001 18:35:57 -0700
OK, I read through the docs and have one question. I am very sorry if I
passed over this in the docs, but usually I have trouble knowing where to
look. Basically, I have to set up a protocol for the setProtocolForProxy
method. I have one set up and it seems to recognize it.
I don't really grasp what I am playing with, so I'll just post my code. What
I want to happen is that when I press the send button, an NSLog will pick up
on it.
Controller.h
----------------------
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
{
IBOutlet id chatField;
IBOutlet id messageField;
NSString *chatText;
}
- (IBAction)sendMessage:(id)sender;
@end
Controller.m
-----------------------
#import "Controller.h"
#import "ServerProtocol.h"
@implementation Controller
- (void)awakeFromNib
{
NSConnection *theConnection;
[chatText init];
theConnection = [NSConnection defaultConnection];
[theConnection setRootObject:chatText];
}
- (IBAction)sendMessage:(id)sender
{
id theProxy;
chatText = [chatField string];
// [chatField setString:[[chatText stringByAppendingString:[messageField
stringValue]] stringByAppendingString:@"\r"]];
chatText = [[chatText stringByAppendingString:[messageField
stringValue]] stringByAppendingString:@"\r"];
theProxy = [[NSConnection
rootProxyForConnectionWithRegisteredName:@"server" host:@"*"] retain];
[theProxy setProtocolForProxy:@protocol(ServerProtocol)];
[messageField setStringValue:@""];
}
@end
ServerProtocol.h
------------------------
#import <Foundation/Foundation.h>
@protocol ServerProtocol
- (void)updateChat:(NSString *)chatText;
@end
@interface ServerProtocol : NSObject
{
}
@end
ServerProtocol.m
-------------------------
#import "ServerProtocol.h"
#import "Controller.h"
@implementation ServerProtocol
- (void)updateChat:(NSString *)chatText
{
NSLog(@"Yeah!");
}
@end
On 10/16/01 3:27 AM, "Ondra Cada" <email@hidden> wrote:
>
Sam,
>
>
>>>>>> Sam Goldman (SG) wrote at Mon, 15 Oct 2001 18:55:43 -0700:
>
SG> What docs, examples, etc. do I need to look at to make a client/server
>
SG> application with Cocoa.
>
>
Both client and server in Cocoa?
>
>
If so, you want Distributed Objects: have a look at NSConnection, and the
>
rest's child's play.
>
---
>
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