예제 #1
0
        /// <summary>
        /// Open Socket listener on specific port
        /// </summary>
        protected void openSocketListener(int port)
        {
            try {
                                #if DEBUG
                log("[2] Opening Listener on port " + port + "...");
                                #endif
                if (httpServer == null)
                {
                    httpServer = new HttpServer(new Server(port));
                }
                socketOpened = true;

                                #if DEBUG
                log("[2] Listener OPENED on port: " + httpServer.Server.Port);
                                #endif

                // Adding Resource Handler.
                IPhoneResourceHandler resourceHandler = new IPhoneResourceHandler(ApplicationSource.FILE);
                //resourceHandler.Substitute = false;
                httpServer.Handlers.Add(resourceHandler);
                httpServer.Handlers.Add(new RemoteResourceHandler(IPhoneServiceLocator.GetInstance()));
            } catch (Exception ex) {
                                #if DEBUG
                log("[2] Cannot open internal server socket: " + ex.Message);
                                #endif
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
                {
                    System.Net.Sockets.SocketException socketException = ex as System.Net.Sockets.SocketException;
                    //log ("[2] Socket exception: " + socketException.SocketErrorCode);
                    if (socketException.SocketErrorCode == System.Net.Sockets.SocketError.AddressAlreadyInUse)
                    {
                                                #if DEBUG
                        log("[2] Address already in use; trying with next port...");
                                                #endif
                        this.openSocketListener(port + 1);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        protected bool openSocketListener(NSDictionary settings)
        {
            bool socketOpened = false;

            try {
                int defaultIPCPort = AppDelegate.GetIPCDefaultPort(settings);
                                #if DEBUG
                log("Opening Listener on port " + defaultIPCPort + "...");
                                #endif
                if (httpServer == null)
                {
                    httpServer = new HttpServer(new Server(defaultIPCPort));
                }
                socketOpened = true;

                                #if DEBUG
                log("Listener OPENED on port: " + httpServer.Server.Port);
                                #endif
                // Adding Resource Handler.
                IPhoneResourceHandler resourceHandler = new IPhoneResourceHandler(ApplicationSource.FILE);
                //resourceHandler.Substitute = false;
                httpServer.Handlers.Add(resourceHandler);

                // Adding Service URI Handler.
                httpServer.Handlers.Add(new IPhoneServiceURIHandler(IPhoneServiceLocator.GetInstance()));

                // Adding Remote Resource Handler.
                httpServer.Handlers.Add(new RemoteResourceHandler(IPhoneServiceLocator.GetInstance()));
            } catch (Exception ex) {
                                #if DEBUG
                log("Cannot open internal server socket: " + ex.Message);
                                #endif
            }

            return(socketOpened);
        }