Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSPort.h |
NSSocketPort
is a subclass of NSPort
that represents a BSD socket. An NSSocketPort
object can be used as an endpoint for distributed object connections. Companion classes, NSMachPort
and NSMessagePort
, allow for local (on the same machine) communication only. The NSSocketPort
class allows for both local and remote communication, but may be more expensive than the others for the local case.
Note: The NSSocketPort
class conforms to the NSCoding
protocol, but only supports coding by an NSPortCoder
. NSPort
and its other subclasses do not support archiving.
– init
– initWithTCPPort:
– initWithProtocolFamily:socketType:protocol:address:
– initWithProtocolFamily:socketType:protocol:socket:
– initRemoteWithTCPPort:host:
– initRemoteWithProtocolFamily:socketType:protocol:address:
Returns the receiver’s socket address structure.
- (NSData *)address
The receiver’s socket address structure stored inside an NSData
object.
– initWithProtocolFamily:socketType:protocol:address:
– initRemoteWithProtocolFamily:socketType:protocol:address:
NSPort.h
Initializes the receiver as a local TCP/IP socket of type SOCK_STREAM
.
- (id)init
An initialized local TCP/IP socket port of type SOCK_STREAM
.
The port number is selected by the system.
NSPort.h
Initializes the receiver as a remote socket with the provided arguments.
- (id)initRemoteWithProtocolFamily:(int)family socketType:(int)type protocol:(int)protocol address:(NSData *)address
The protocol family for the socket port.
The type of socket.
The specific protocol to use from the the protocol family.
The family-specific socket address for the receiver copied into an NSData
object.
A connection is not opened to the remote address until data is sent.
NSPort.h
Initializes the receiver as a TCP/IP socket of type SOCK_STREAM
that can connect to a remote host on a specified port.
- (id)initRemoteWithTCPPort:(unsigned short)port host:(NSString *)hostName
The port to connect to.
The host name to connect to. hostName may be either a host name or an IPv4-style address.
A TCP/IP socket port of type SOCK_STREAM
that can connect to the remote host hostName on port port.
A connection is not opened to the remote host until data is sent.
NSPort.h
Initializes the receiver as a local socket with the provided arguments.
- (id)initWithProtocolFamily:(int)family socketType:(int)type protocol:(int)protocol address:(NSData *)address
The protocol family for the socket port.
The type of socket.
The specific protocol to use from the the protocol family.
The family-specific socket address for the receiver copied into an NSData
object.
A local socket port initialized with the provided arguments.
The receiver must be added to a run loop before it can accept connections or receive messages. Incoming messages are passed to the receiver’s delegate method handlePortMessage:
.
To create a standard TCP/IP socket, use initWithTCPPort:
.
NSPort.h
Initializes the receiver with a previously created local socket.
- (id)initWithProtocolFamily:(int)family socketType:(int)type protocol:(int)protocol socket:(NSSocketNativeHandle)sock
The protocol family for the provided socket.
The type of the provided socket.
The specific protocol the provided socket uses.
The previously created socket.
A local socket port initialized with the provided socket.
NSPort.h
Initializes the receiver as a local TCP/IP socket of type SOCK_STREAM
, listening on a specified port number.
- (id)initWithTCPPort:(unsigned short)port
The port number for the newly created socket port to listen on. If port is 0, the system will assign a port number.
An initialized local TCP/IP socket of type SOCK_STREAM
, listening on port port.
NSPort.h
Returns the protocol that the receiver uses for communication.
- (int)protocol
The protocol the receiver uses for communication.
NSPort.h
Returns the protocol family that the receiver uses for communication.
- (int)protocolFamily
The protocol family the receiver uses for communication.
NSPort.h
Returns the receiver’s native socket identifier on the platform.
- (NSSocketNativeHandle)socket
The native socket identifier on the platform. For Mac OS X, this is an integer file descriptor.
NSPort.h
Returns the receiver’s socket type.
- (int)socketType
The receiver's socket type.
NSPort.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)