EDTCPSocket


Inherits From:
EDIPSocket
Declared In:
EDTCPSocket.h


Class Description

This class implementes TCP sockets and some methods specific to such sockets. Most of the commonly used functionality is in its superclasses EDIPSocket and NSFileHandle as well as in the NSFileHandle category defined in this framework.

The following code example shows how to set up a client socket, and connect it to Apple's web server:     
    
    EDTCPSocket *socket;
    
    socket = [EDTCPSocket socket];
    [socket connectToHost:[NSHost hostWithName:hostname] port:80]
    

The following code example shows how to set up a server socket, listening on the standard web port on all interfaces of this host. If we are debugging it sets the "re-use address" option so that we don't have to wait to set up the socket after restarting our application:     
    
    EDTCPSocket *socket;
    
    socket = [EDTCPSocket socket];
    #if DEBUG
    [socket setAllowsAddressReuse:YES];
    #endif
    [socket startListeningOnLocalPort:80];
    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(newClientNotification:)
    name:NSFileHandleConnectionAcceptedNotification
    object:socket];
    [socket acceptConnectionInBackgroundAndNotify];
    
    

Note that, generally, working with EDStreams is a better choice than working directly with sockets.


Method Types

Setting socket options
- setSendsDataImmediately:
Server sockets
- startListening
- startListeningOnLocalPort:
- startListeningOnLocalPort:andAddress:

Instance Methods

setSendsDataImmediately:

- (void)setSendsDataImmediately:(BOOL)flag

Controls wether data written to the socket is sent immediatly or whether the operating system should try to accumulate some data before sending a packet to reduce overhead. This is commonly known as Nagle's algorithm (RFC 896) and corresponds to TCP_NODELAY.


startListening

- (void)startListening

Starts listening for incoming connections. This requires that a local port has been set before. Note that acceptConnectionInBackgroundAndNotify must be called afterwards so that incoming connections are handled.


startListeningOnLocalPort:

- (void)startListeningOnLocalPort:(unsigned short)aPort

Starts listening for incoming connections on aPort on all local IP addresses (interfaces). Note that acceptConnectionInBackgroundAndNotify must be called afterwards so that incoming connections are handled.


startListeningOnLocalPort:andAddress:

- (void)startListeningOnLocalPort:(unsigned short)aPort andAddress:(NSString *)addressString

Starts listening for incoming connections on the aPort on the specified local address; the latter being in the "typical" dotted numerical notation. Note that acceptConnectionInBackgroundAndNotify must be called afterwards so that incoming connections are handled.


Version 2.0 Copyright ©2002. All Rights Reserved.