EDSocket


Inherits From:
NSFileHandle
Declared In:
EDSocket.h


Class Description

This class and its subclasses provide an object-oriented interface for socket programming. EDSocket inherits from NSFileHandle and acts as a common base class. This is a fairly natural choice as a socket is really a special file handle and NSFileHandle actually contains some useful methods to deal with socket functionality, acceptConnectionInBackgroundAndNotify for example. However, NSFileHandle does not provide a means to create and connect sockets. The interesting part is that NSFileHandle (in Apple's implementation) is a class cluster and all the caveats of subclassing such a thing apply. Hence, most of the code in EDSocket is dealing with general infrastructure. At the moment there is only on subclass, namely EDIPSocket representing the protocol family inet. There are, however, a lot of other families that you might want to support; Unix domain sockets or Appletalk for example.

Note that some socket related functionality is implemented in a category on NSFileHandle.


Instance Variables

NSFileHandle *realHandle;

realHandleAll instance variables are private.


Method Types

Describing socket classes
+ protocolFamily
+ socketType
+ socketProtocol
Creating new sockets
+ socket
- init
- initWithFileHandle:
Setting socket options
- setSocketOption:level:value:
- setSocketOption:level:timeValue:


Class Methods

protocolFamily

+ (int)protocolFamily

Must be overriden to return the protocol family for the socket class; for example PF_INET for IP sockets.


socket

+ (id)socket

Creates and returns a socket. Of course, subclasses inherit this method which means a TCP socket can be created as [EDTCPSocket socket].


socketProtocol

+ (int)socketProtocol

Must be overriden to return the protocol for the socket class; for example IPPROTO_TCP for TCP sockets.


socketType

+ (int)socketType

Must be overriden to return the type for the socket class; for example SOCK_STREAM for TCP sockets.


Instance Methods

init

- (id)init

Initialises a newly allocated socket by creating a POSIX socket with the protocol family, protocol and type as defined by the corresponding class methods.


initWithFileHandle:

- (id)initWithFileHandle:(NSFileHandle *)aFileHandle

Initialises a newly allocated socket by wrapping aFileHandle. The file handle's file descriptor must represent a socket.


setSocketOption:level:timeValue:

- (void)setSocketOption:(int)anOption level:(int)aLevel timeValue:(NSTimeInterval)timeout

Sets the socket option described by anOption on protocol level aLevel to timeout. You should not call this method directly but use the "appropriatly" named methods in subclasses, e.g. setSendTimeout:.


setSocketOption:level:value:

- (void)setSocketOption:(int)anOption level:(int)aLevel value:(int)value

Sets the socket option described by anOption on protocol level aLevel to value. You should not call this method directly but use the "appropriatly" named methods in subclasses, e.g. setAllowsAddressReuse: or setSendsDataImmediately:.


Version 2.0 Copyright ©2002. All Rights Reserved.