Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mindwalkernine

macrumors newbie
Original poster
Jul 23, 2006
9
0
I'm trying to get my client application to send a tiff to be composited on the server application's view. Could someone help me out?

I also don't know how to write protocols for this code. Could someone give me a hand with that?

Here's all of my server and client code:

Code:
---------- CLIENT CODE ----------
/* MyView */

#import <Cocoa/Cocoa.h>

@interface MyView : NSView
{	
	NSImage *myImage;
}

- (void)setImage:(NSImage *)image;

@end

#import "MyView.h"

@implementation MyView

- (id)initWithFrame:(NSRect)frameRect
{
	if ((self = [super initWithFrame:frameRect]) != nil)
	{
		
	}
	
	return self;
}

- (void)setImage:(NSImage *)image
{
	[image retain];
	
	[myImage release];
	
	myImage = image;
	
	[self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)rect
{
	NSRect bounds = [self bounds];
	
	if(myImage)
	{
		NSRect imageRect;
		NSRect drawingRect;
		
		imageRect.origin = NSZeroPoint;
		imageRect.size = [myImage size];
		drawingRect = imageRect;
		[myImage
			drawInRect:drawingRect
			fromRect:imageRect
			operation:NSCompositeSourceOver
			fraction:1.0
		];
	}
	else
		NSLog(@"Did not draw myImage.");
}

@end


/* Controller */

#import <Cocoa/Cocoa.h>

#import "MyView.h"

@interface Controller : NSObject
{
	NSSocketPort *port;
	NSConnection *connection;

	IBOutlet NSView *myView;
}

- (void)setImage:(NSImage *)image;

- (IBAction)vendService:(id)sender;

@end

#import "Controller.h"

@implementation Controller

- (void)setImage:(NSImage *)image
{
	[myView setImage:image];
}

- (IBAction)vendService:(id)sender
{
	port = [[NSSocketPort alloc] initWithTCPPort:12345];
	
	connection = [[NSConnection connectionWithReceivePort:port sendPort:nil] retain];
	
	[connection setRootObject:self];
	
	if(![[NSSocketPortNameServer sharedInstance] registerPort:port name:@"server"]) 
	{
		NSLog(@"Could not register name of server.");
	}
}

@end

---------- CLIENT CODE ----------
/* Controller */

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject
{
    IBOutlet NSTextField *messageField;
	
	NSSocketPort *port;
	NSConnection *connection;
	NSDistantObject *proxy;
	
	NSImage *anImage;
}

- (IBAction)createProxy:(id)sender;
- (IBAction)sendImage:(id)sender;

@end


#import "Controller.h"

@implementation Controller

- (id)init 
{
    self = [super init];
   
   if ( self )
	{
		anImage = [[NSImage alloc] initWithContentsOfFile:@"/users/jordanevans/desktop/snapshot.tiff"];
		[anImage retain];
    }
	
   return self;
}

- (IBAction)createProxy:(id)sender
{
	port = [[NSSocketPortNameServer sharedInstance] portForName:@"server" host:@"*"];
		
	connection = [NSConnection connectionWithReceivePort:nil sendPort:port];
		
	proxy = [[connection rootProxy] retain];
	
}

- (IBAction)sendImage:(id)sender
{
	if( ![proxy setImage:anImage] )
	{
		NSLog(@"Did not set send image.");
	}
}

@end
 

mindwalkernine

macrumors newbie
Original poster
Jul 23, 2006
9
0
csubear said:
I haven't looked at your code but take a look at this

http://cocoadevcentral.com/articles/000062.php

it may or may not help you.

That is the problem with many examples. It tries to teach way too many things at once. I looked at it, and it's spaghetti with alot of bad names. It also got bad reviews.

I provided a bare bones example with no extras, which if we get this thing fixed, others can look and learn from it's simplicity.

The author says he is going to get down to basics of DO, but instead he throws in a bunch of concepts most people may not know about. Bad way to tutorialize. One concept at a time is best.

I quote him:
AUTHOR said:
but it will get the basics down. Most importantly, it's a vehicle to cover a diverse range of topics:

Distributed Objects - Getting the client & server to talk to each other
Split Views, TableViews, and other GUI Tricks - An introduction to some of the less obvious Cocoa user interface components
Multiple Nib Files - Using more than one Nib in a program, covering fun things like that funny 'File Owner' icon in Interface Builder
Exception Handling - Objective-C's exception handling mechanism
And maybe a few Odds & Ends along the way
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.