![]() |
IOS Streaming Browser 1.0
An IOS streaming browser to stream the display to others or to a projector
|
00001 #import <Foundation/Foundation.h> 00002 00003 @class GCDAsyncSocket; 00004 @class WebSocket; 00005 00006 #if TARGET_OS_IPHONE 00007 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 // iPhone 4.0 00008 #define IMPLEMENTED_PROTOCOLS <NSNetServiceDelegate> 00009 #else 00010 #define IMPLEMENTED_PROTOCOLS 00011 #endif 00012 #else 00013 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 // Mac OS X 10.6 00014 #define IMPLEMENTED_PROTOCOLS <NSNetServiceDelegate> 00015 #else 00016 #define IMPLEMENTED_PROTOCOLS 00017 #endif 00018 #endif 00019 00020 00021 @interface HTTPServer : NSObject IMPLEMENTED_PROTOCOLS 00022 { 00023 ///////////////////////////////////////////// 00024 // Underlying asynchronous TCP/IP socket 00025 //////////////////////////////////////////// 00026 00027 /** 00028 Dispatch queues are lightweight objects to which blocks may be submitted. The system manages a pool of threads which process dispatch queues and invoke blocks submitted to them. 00029 **/ 00030 dispatch_queue_t serverQueue; 00031 00032 /** 00033 Dispatch queues are lightweight objects to which blocks may be submitted. The system manages a pool of threads which process dispatch queues and invoke blocks submitted to them. 00034 **/ 00035 dispatch_queue_t connectionQueue; 00036 00037 /** 00038 for reading and writing data 00039 **/ 00040 GCDAsyncSocket *asyncSocket; 00041 00042 /////////////////////////////////////////// 00043 // HTTP server configuration 00044 /////////////////////////////////////////// 00045 00046 00047 /** 00048 the document root 00049 **/ 00050 NSString *documentRoot; 00051 00052 /** 00053 default is HTTP connection 00054 **/ 00055 Class connectionClass; 00056 00057 /** 00058 the interface the server should listen on, "en1", "lo0", etc 00059 **/ 00060 NSString *interface; 00061 00062 /** 00063 the listening port 00064 **/ 00065 UInt16 port; 00066 00067 /////////////////////////////////////////// 00068 // NSNetService and related variables 00069 /////////////////////////////////////////// 00070 00071 /** 00072 represents a network service 00073 **/ 00074 NSNetService *netService; 00075 00076 /** 00077 the domain the service should be published on, the default is 'local' 00078 **/ 00079 NSString *domain; 00080 00081 /** 00082 tcp or udp 00083 **/ 00084 NSString *type; 00085 00086 /** 00087 default is the computers name that the server is running on 00088 **/ 00089 NSString *name; 00090 00091 /** 00092 the published server name 00093 **/ 00094 NSString *publishedName; 00095 00096 /** 00097 00098 **/ 00099 NSDictionary *txtRecordDictionary; 00100 00101 /////////////////////////////////////////// 00102 // Connection management 00103 /////////////////////////////////////////// 00104 00105 /** 00106 the connections to the server 00107 **/ 00108 NSMutableArray *connections; 00109 00110 /** 00111 the web socket connections 00112 **/ 00113 NSMutableArray *webSockets; 00114 00115 /** 00116 locks the http connection 00117 **/ 00118 NSLock *connectionsLock; 00119 00120 /** 00121 locks the websocket 00122 **/ 00123 NSLock *webSocketsLock; 00124 00125 // Whether the server is running or not 00126 BOOL isRunning; 00127 } 00128 00129 /** 00130 * Specifies the document root to serve files from. 00131 * For example, if you set this to "/Users/<your_username>/Sites", 00132 * then it will serve files out of the local Sites directory (including subdirectories). 00133 * 00134 * The default value is nil. 00135 * The default server configuration will not serve any files until this is set. 00136 * 00137 * If you change the documentRoot while the server is running, 00138 * the change will affect future incoming http connections. 00139 **/ 00140 - (NSString *)documentRoot; 00141 00142 /** 00143 Sets the document root 00144 **/ 00145 - (void)setDocumentRoot:(NSString *)value; 00146 00147 /** 00148 * The connection class is the class used to handle incoming HTTP connections. 00149 * 00150 * The default value is [HTTPConnection class]. 00151 * You can override HTTPConnection, and then set this to [MyHTTPConnection class]. 00152 * 00153 * If you change the connectionClass while the server is running, 00154 * the change will affect future incoming http connections. 00155 **/ 00156 - (Class)connectionClass; 00157 00158 /** 00159 Sets the connection class 00160 **/ 00161 - (void)setConnectionClass:(Class)value; 00162 00163 /** 00164 * Set what interface you'd like the server to listen on. 00165 * By default this is nil, which causes the server to listen on all available interfaces like en1, wifi etc. 00166 * 00167 * The interface may be specified by name (e.g. "en1" or "lo0") or by IP address (e.g. "192.168.4.34"). 00168 * You may also use the special strings "localhost" or "loopback" to specify that 00169 * the socket only accept connections from the local machine. 00170 **/ 00171 - (NSString *)interface; 00172 00173 /** 00174 Sets the interface 00175 **/ 00176 - (void)setInterface:(NSString *)value; 00177 00178 /** 00179 * The port number to run the HTTP server on. 00180 * 00181 * The default port number is zero, meaning the server will automatically use any available port. 00182 * This is the recommended port value, as it avoids possible port conflicts with other applications. 00183 * Technologies such as Bonjour can be used to allow other applications to automatically discover the port number. 00184 * 00185 * Note: As is common on most OS's, you need root privledges to bind to port numbers below 1024. 00186 * 00187 * You can change the port property while the server is running, but it won't affect the running server. 00188 * To actually change the port the server is listening for connections on you'll need to restart the server. 00189 * 00190 * The listeningPort method will always return the port number the running server is listening for connections on. 00191 * If the server is not running this method returns 0. 00192 **/ 00193 - (UInt16)port; 00194 00195 /** 00196 Gets the listening port 00197 **/ 00198 - (UInt16)listeningPort; 00199 00200 /** 00201 Sets the listening port 00202 **/ 00203 - (void)setPort:(UInt16)value; 00204 00205 /** 00206 * Bonjour domain for publishing the service. 00207 * The default value is "local.". 00208 * 00209 * Note: Bonjour publishing requires you set a type. 00210 * 00211 * If you change the domain property after the bonjour service has already been published (server already started), 00212 * you'll need to invoke the republishBonjour method to update the broadcasted bonjour service. 00213 **/ 00214 - (NSString *)domain; 00215 00216 /** 00217 Sets the domain 00218 **/ 00219 - (void)setDomain:(NSString *)value; 00220 00221 /** 00222 * Bonjour name for publishing the service. 00223 * The default value is "". 00224 * 00225 * If using an empty string ("") for the service name when registering, 00226 * the system will automatically use the "Computer Name". 00227 * Using an empty string will also handle name conflicts 00228 * by automatically appending a digit to the end of the name. 00229 * 00230 * Note: Bonjour publishing requires you set a type. 00231 * 00232 * If you change the name after the bonjour service has already been published (server already started), 00233 * you'll need to invoke the republishBonjour method to update the broadcasted bonjour service. 00234 * 00235 * The publishedName method will always return the actual name that was published via the bonjour service. 00236 * If the service is not running this method returns nil. 00237 **/ 00238 - (NSString *)name; 00239 00240 /** 00241 Gets the published name of the server 00242 **/ 00243 - (NSString *)publishedName; 00244 00245 /** 00246 Sets the published name of the server 00247 **/ 00248 - (void)setName:(NSString *)value; 00249 00250 /** 00251 * Bonjour type for publishing the service. 00252 * The default value is nil. 00253 * The service will not be published via bonjour unless the type is set. 00254 * 00255 * If you wish to publish the service as a traditional HTTP server, you should set the type to be "_http._tcp.". 00256 * 00257 * If you change the type after the bonjour service has already been published (server already started), 00258 * you'll need to invoke the republishBonjour method to update the broadcasted bonjour service. 00259 **/ 00260 - (NSString *)type; 00261 00262 /** 00263 Set the type of service to be published via Bonjour param NSString 00264 **/ 00265 - (void)setType:(NSString *)value; 00266 00267 /** 00268 * Republishes the service via bonjour if the server is running. 00269 * If the service was not previously published, this method will publish it (if the server is running). 00270 **/ 00271 - (void)republishBonjour; 00272 00273 /** 00274 * Gets the TXT record dictionary 00275 **/ 00276 - (NSDictionary *)TXTRecordDictionary; 00277 00278 /** 00279 Sets the TXT record dictionary 00280 **/ 00281 - (void)setTXTRecordDictionary:(NSDictionary *)dict; 00282 00283 /** 00284 Starts the server 00285 **/ 00286 - (BOOL)start:(NSError **)errPtr; 00287 00288 /** 00289 Stops the server 00290 **/ 00291 - (BOOL)stop; 00292 00293 /** 00294 Whether the server is running 00295 **/ 00296 - (BOOL)isRunning; 00297 00298 /** 00299 Adds a web socket 00300 **/ 00301 - (void)addWebSocket:(WebSocket *)ws; 00302 00303 /** 00304 Gets the number of HTTP connections 00305 **/ 00306 - (NSUInteger)numberOfHTTPConnections; 00307 00308 /** 00309 Gets the number of web socket connections 00310 **/ 00311 - (NSUInteger)numberOfWebSocketConnections; 00312 00313 @end