NSSocketPort Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.0 and later. |
| Companion guide | |
| Declared in | NSPort.h |
Overview
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.
Tasks
Creating Instances
-
– init -
– initWithTCPPort: -
– initWithProtocolFamily:socketType:protocol:address: -
– initWithProtocolFamily:socketType:protocol:socket: -
– initRemoteWithTCPPort:host: -
– initRemoteWithProtocolFamily:socketType:protocol:address:
Getting Information
Instance Methods
address
Returns the receiver’s socket address structure.
Return Value
The receiver’s socket address structure stored inside an NSData object.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPort.hinit
Initializes the receiver as a local TCP/IP socket of type SOCK_STREAM.
Return Value
An initialized local TCP/IP socket port of type SOCK_STREAM.
Discussion
The port number is selected by the system.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hinitRemoteWithProtocolFamily:socketType:protocol:address:
Initializes the receiver as a remote socket with the provided arguments.
Parameters
- family
The protocol family for the socket port.
- type
The type of socket.
- protocol
The specific protocol to use from the the protocol family.
- address
The family-specific socket address for the receiver copied into an
NSDataobject.
Discussion
A connection is not opened to the remote address until data is sent.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSPort.hinitRemoteWithTCPPort:host:
Initializes the receiver as a TCP/IP socket of type SOCK_STREAM that can connect to a remote host on a specified port.
Parameters
- port
The port to connect to.
- hostName
The host name to connect to. hostName may be either a host name or an IPv4-style address.
Return Value
A TCP/IP socket port of type SOCK_STREAM that can connect to the remote host hostName on port port.
Discussion
A connection is not opened to the remote host until data is sent.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hinitWithProtocolFamily:socketType:protocol:address:
Initializes the receiver as a local socket with the provided arguments.
Parameters
- family
The protocol family for the socket port.
- type
The type of socket.
- protocol
The specific protocol to use from the the protocol family.
- address
The family-specific socket address for the receiver copied into an
NSDataobject.
Return Value
A local socket port initialized with the provided arguments.
Discussion
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:.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hinitWithProtocolFamily:socketType:protocol:socket:
Initializes the receiver with a previously created local socket.
Parameters
- family
The protocol family for the provided socket.
- type
The type of the provided socket.
- protocol
The specific protocol the provided socket uses.
- sock
The previously created socket.
Return Value
A local socket port initialized with the provided socket.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hinitWithTCPPort:
Initializes the receiver as a local TCP/IP socket of type SOCK_STREAM, listening on a specified port number.
Parameters
- port
The port number for the newly created socket port to listen on. If port is 0, the system will assign a port number.
Return Value
An initialized local TCP/IP socket of type SOCK_STREAM, listening on port port.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hprotocol
Returns the protocol that the receiver uses for communication.
Return Value
The protocol the receiver uses for communication.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hprotocolFamily
Returns the protocol family that the receiver uses for communication.
Return Value
The protocol family the receiver uses for communication.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.hsocket
Returns the receiver’s native socket identifier on the platform.
Return Value
The native socket identifier on the platform. For OS X, this is an integer file descriptor.
Availability
- Available in OS X v10.0 and later.
Declared In
NSPort.h© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)