PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSPortMessage


Inherits from:
NSObject
Conforms to:
NSObject
(NSObject)
Declared in:
Foundation/NSPortMessage.h




Class Description


An NSPortMessage defines a low level, operating-system independent type for interapplication (and interthread) messages. NSPortMessages are used primarily by the distributed objects system. You should implement interapplication communication using distributed objects whenever possible, and use NSPortMessages only when necessary.

An NSPortMessage has three major parts: the send and receive ports, which are NSPorts that link the sender of the message to the receiver, and the components, which form the body of the message. The components are held as an NSArray of NSData and NSPort objects. NSPortMessage's sendBeforeDate: message sends the components out through the send port; any replies to the message arrive on the receive port. See the NSPort class specification for information on handling incoming messages.

An NSPortMessage can be initialized with a pair of NSPorts and an NSArray of components. An NSPortMessage's body can contain only NSPort objects or NSData objects. In the distributed objects system the byte/character arrays are usually encoded NSInvocations that are being forwarded from a proxy to the corresponding real object.

An NSPortMessage also maintains a message identifier, which can be used to indicate the class of a message, such as an Objective-C method invocation, a connection request, an error, and so on. Use the setMsgid: and msgid methods to access the identifier.




Method Types


Creating instances
- initWithSendPort:receivePort:components:
Sending the message
- sendBeforeDate:
Getting the components
- components
Getting the ports
- receivePort
- sendPort
Accessing the message ID
- setMsgid:
- msgid


Instance Methods



components

- (NSArray *)components

Returns the data components of the receiver. See the class description for more information.

initWithSendPort:receivePort:components:

- (id)initWithSendPort:(NSPort *)sendPort receivePort:(NSPort *)receivePort components:(NSArray *)components

Initializes a newly allocated NSPortMessage to send the data in components on sendPort. Replies to the message will arrive on receivePort. An NSPortMessage initialized with this method has a message identifier of 0. This is the designated initializer for NSPortMessage.

components should contain only NSData and NSPort objects, and the contents of the NSData objects should be in network byte order.

See Also: - setMsgid:



msgid

- (unsigned)msgid

Returns the identifier for the receiver. Cooperating applications can use this to define different types of messages, such as connection requests, RPCs, errors, and so on.

See Also: - setMsgid:



receivePort

- (NSPort *)receivePort

For an outgoing message, returns the NSPort on which replies to the NSPortMessage will arrive. For an incoming message, returns the NSPort the NSPortMessage did arrive on.

See Also: - sendPort



sendBeforeDate:

- (BOOL)sendBeforeDate:(NSDate *)aDate

Attempts to send the message before aDate, returning YES if successful, NO otherwise. See the NSPort class specification for information on receiving an NSPortMessage.

sendPort

- (NSPort *)sendPort

For an outgoing message, returns the NSPort the NSPortMessage will send itself through when it receives a sendBeforeDate: message. For an incoming message, returns the NSPort replies to the NSPortMessage should be sent through.

See Also: - receivePort



setMsgid:

- (void)setMsgid:(unsigned)msgid

Sets the identifier for the receiver to msgid. Cooperating applications can use this to define different types of messages, such as connection requests, RPCs, errors, and so on.

See Also: - msgid




Table of Contents