コード例 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void Init(DaemonContext context)
        {
            System.Console.Error.WriteLine("Initializing privileged NFS client socket...");
            NfsConfiguration conf = new NfsConfiguration();
            int clientPort        = conf.GetInt(NfsConfigKeys.DfsNfsRegistrationPortKey, NfsConfigKeys
                                                .DfsNfsRegistrationPortDefault);

            if (clientPort < 1 || clientPort > 1023)
            {
                throw new RuntimeException("Must start privileged NFS server with '" + NfsConfigKeys
                                           .DfsNfsRegistrationPortKey + "' configured to a " + "privileged port.");
            }
            registrationSocket = new DatagramSocket(new IPEndPoint("localhost", clientPort));
            registrationSocket.SetReuseAddress(true);
            args = context.GetArguments();
        }
コード例 #2
0
        /// <summary>Checks to see if a specific port is available.</summary>
        /// <remarks>
        /// Checks to see if a specific port is available.
        /// <br />
        /// Source: Apache's mina project, via stack overflow
        /// http://stackoverflow.com/questions/434718/
        /// sockets-discover-port-availability-using-java
        /// </remarks>
        /// <param name="port">the port to check for availability</param>
        public static bool Available(int port)
        {
            ServerSocket   ss = null;
            DatagramSocket ds = null;

            try
            {
                ss = new ServerSocket(port);
                ss.SetReuseAddress(true);
                ds = new DatagramSocket(port);
                ds.SetReuseAddress(true);
                return(true);
            }
            catch (IOException)
            {
            }
            finally
            {
                if (ds != null)
                {
                    ds.Close();
                }
                if (ss != null)
                {
                    try
                    {
                        ss.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
            // should not be thrown
            return(false);
        }