5 // Created by Alexander Strange on Tue Feb 11 2003.
6 // Copyright (c) 2003 __MyCompanyName__. All rights reserved.
9 #import <Foundation/Foundation.h>
10 #import <netinet/in.h>
12 #import "ITByteStream.h"
15 * @header ITInetSocket
16 * @abstract Definitions for the ITInetSocket class
20 * @constant ITInetMaxConnections
21 * @abstract The maximum number of running ITInetSockets you can have.
22 * @discussion The socket will error during a connection request if you are over the maximum.
26 ITInetMaxConnections = 128
30 * @enum ITInetSocketState
31 * @abstract Possible states of a socket
32 * @constant ITInetSocketConnecting The socket is negotiating a connection.
33 * @constant ITInetSocketListening The socket is a server socket.
34 * @constant ITInetSocketReading The socket is reading data from the other side.
35 * @constant ITInetSocketWriting The socket is sending data to the other side.
36 * @constant ITInetSocketDisconnected The socket does not have a connection.
39 ITInetSocketConnecting,
40 ITInetSocketListening,
43 ITInetSocketDisconnected
47 * @enum ITInetSocketError
48 * @abstract Possible error conditions of a socket
49 * @constant ITInetHostNotFound The host specified does not actually exist.
50 * @constant ITInetConnectionDropped The remote side dropped the connection.
51 * @constant ITInetCouldNotConnect The socket was unable to connect for some reason
55 ITInetConnectionDropped,
62 * @protocol ITInetSocketDelegate
63 * @abstract Delegate methods for ITInetSocket
64 * @discussion ITInetSockets use these methods to communicate with their delegates
66 @protocol ITInetSocketDelegate
68 * @method dataRecieved:
69 * @abstract Alerts the delegate of data.
70 * @discussion The delegate should check [sender readPipe] to get the data.
71 * @param sender The socket that the messages came from.
73 - (void) dataRecieved:(ITInetSocket *)sender;
75 * @method errorOccured:during:onSocket:
76 * @abstract Alerts the delegate of an error condition.
77 * @discussion The delegate can try retryCondition.
78 * @param err The error class.
79 * @param state What the socket was doing when the error occured.
80 * @param sender The socket the error occured on.
82 - (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(ITInetSocket*)sender;
84 * @method finishedConnecting:
85 * @abstract Alerts the delegate of a successful connection attempt.
86 * @discussion The delegate should send whatever initial data is required for the protocol (nickname for IRC, etc.)
87 * @param sender The socket that established the connection.
89 - (void) finishedConnecting:(ITInetSocket *)sender;
94 * @abstract An Internet socket class.
95 * @discussion ITInetSocket is an Internet socket class supporting IPv6 and Rendezvous.
97 @interface ITInetSocket : NSObject {
102 struct addrinfo *ai, *ai_cur;
103 ITByteStream *readPipe, *writePipe;
104 ITInetSocketState state;
107 +(void)startAutoconnectingToService:(NSString*)type delegate:(id <ITInetSocketDelegate>)d;
108 -(id) initWithFD:(int)fd delegate:(id <ITInetSocketDelegate>)d;
109 -(id) initWithDelegate:(id <ITInetSocketDelegate>)d;
111 -(id <ITInetSocketDelegate>)delegate;
112 -(void) connectToHost:(NSString*)host onPort:(short)port;
113 -(void) connectToHost:(NSString*)host onNamedPort:(NSString*)port;
114 -(void) connectWithSockaddrArray:(NSArray*)arr;
115 -(ITInetSocketState) state;
116 -(void) retryConnection;