• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSImage From Client to Server
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage From Client to Server


  • Subject: NSImage From Client to Server
  • From: "Jordan Evans" <email@hidden>
  • Date: Sun, 23 Jul 2006 15:58:17 -0700

I'm trying to get my client application to send a tiff to be
composited on the server application's NSView.  Could someone help me
out?

I also don't know how to write protocols Distributed Objects over the
network.  Could someone give me a hand with that on this code?

Here's all of my server and client 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
		];
	}
}

@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/mycomputer/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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSImage From Client to Server
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: using new APIs with old OS versions
  • Next by Date: Re: Finder-like color label menu item in Cocoa?
  • Previous by thread: Re: using new APIs with old OS versions
  • Next by thread: Re: NSImage From Client to Server
  • Index(es):
    • Date
    • Thread