/// <summary>
        /// Create a new instance of a <code>OncRpcUdpServerTransport</code> which
        /// encapsulates UDP/IP-based XDR streams of an ONC/RPC server.
        /// </summary>
        /// <remarks>
        /// Create a new instance of a <code>OncRpcUdpServerTransport</code> which
        /// encapsulates UDP/IP-based XDR streams of an ONC/RPC server. Using a
        /// server transport, ONC/RPC calls are received and the corresponding
        /// replies are sent back.
        /// This constructor is a convenience constructor for those transports
        /// handling only a single ONC/RPC program and version number.
        /// </remarks>
        /// <param name="dispatcher">
        /// Reference to interface of an object capable of
        /// dispatching (handling) ONC/RPC calls.
        /// </param>
        /// <param name="bindAddr">The local Internet Address the server will bind to.</param>
        /// <param name="port">
        /// Number of port where the server will wait for incoming
        /// calls.
        /// </param>
        /// <param name="info">
        /// Array of program and version number tuples of the ONC/RPC
        /// programs and versions handled by this transport.
        /// </param>
        /// <param name="bufferSize">
        /// Size of buffer for receiving and sending UDP/IP
        /// datagrams containing ONC/RPC call and reply messages.
        /// </param>
        /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public OncRpcUdpServerTransport(OncRpcDispatchable dispatcher
                                        , IPAddress bindAddr, int port, OncRpcServerTransportRegistrationInfo
                                        [] info, int bufferSize) : base(dispatcher, port, info)
        {
            //
            // Make sure the buffer is large enough and resize system buffers
            // accordingly, if possible.
            //
            if (bufferSize < 1024)
            {
                bufferSize = 1024;
            }
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            if (bindAddr == null)
            {
                bindAddr = IPAddress.Any;
            }
            IPEndPoint localEP = new IPEndPoint(bindAddr, port);

            socket.Bind(localEP);
            if (port == 0)
            {
                this.port = ((IPEndPoint)(socket.LocalEndPoint)).Port;
            }
            if (socket.SendBufferSize < bufferSize)
            {
                socket.SendBufferSize = bufferSize;
            }
            if (socket.ReceiveBufferSize < bufferSize)
            {
                socket.ReceiveBufferSize = bufferSize;
            }
            //
            // Create the necessary encoding and decoding streams, so we can
            // communicate at all.
            //
            sendingXdr   = new org.acplt.oncrpc.XdrUdpEncodingStream(socket, bufferSize);
            receivingXdr = new org.acplt.oncrpc.XdrUdpDecodingStream(socket, bufferSize);
        }
 /// <summary>
 /// Close the connection to an ONC/RPC server and free all network-related
 /// resources.
 /// </summary>
 /// <remarks>
 /// Close the connection to an ONC/RPC server and free all network-related
 /// resources. Well -- at least hope, that the Java VM will sometimes free
 /// some resources. Sigh.
 /// </remarks>
 /// <exception cref="OncRpcException">if an ONC/RPC error occurs.</exception>
 /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
 public override void close()
 {
     if (socket != null)
     {
         socket.Close();
         socket = null;
     }
     if (sendingXdr != null)
     {
         try
         {
             sendingXdr.Close();
         }
         catch (System.IO.IOException)
         {
         }
         sendingXdr = null;
     }
     if (receivingXdr != null)
     {
         try
         {
             receivingXdr.Close();
         }
         catch (System.IO.IOException)
         {
         }
         receivingXdr = null;
     }
 }
        /// <summary>
        /// Constructs a new <code>OncRpcUdpClient</code> object, which connects
        /// to the ONC/RPC server at <code>host</code> for calling remote procedures
        /// of the given { program, version }.
        /// </summary>
        /// <remarks>
        /// Constructs a new <code>OncRpcUdpClient</code> object, which connects
        /// to the ONC/RPC server at <code>host</code> for calling remote procedures
        /// of the given { program, version }.
        /// <p>Note that the construction of an <code>OncRpcUdpProtocolClient</code>
        /// object will result in communication with the portmap process at
        /// <code>host</code> if <code>port</code> is <code>0</code>.
        /// </remarks>
        /// <param name="host">The host where the ONC/RPC server resides.</param>
        /// <param name="program">Program number of the ONC/RPC server to call.</param>
        /// <param name="version">Program version number.</param>
        /// <param name="port">
        /// The port number where the ONC/RPC server can be contacted.
        /// If <code>0</code>, then the <code>OncRpcUdpClient</code> object will
        /// ask the portmapper at <code>host</code> for the port number.
        /// </param>
        /// <param name="bufferSize">
        /// The buffer size used for sending and receiving UDP
        /// datagrams.
        /// </param>
        /// <exception cref="OncRpcException">if an ONC/RPC error occurs.</exception>
        /// <exception cref="System.IO.IOException">if an I/O error occurs.</exception>
        /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
        public OncRpcUdpClient(IPAddress host, int program, int version, int port
			, int bufferSize, bool useSecurePort)
            : base(host, program, version, port, OncRpcProtocols
			.ONCRPC_UDP)
        {
            retransmissionTimeout = base.getTimeout();

            //
            // Construct the inherited part of our object. This will also try to
            // lookup the port of the desired ONC/RPC server, if no port number
            // was specified (port = 0).
            //
            //
            // Let the host operating system choose which port (and network
            // interface) to use. Then set the buffer sizes for sending and
            // receiving UDP datagrams. Finally set the destination of packets.
            //
            if (bufferSize < 1024)
            {
                bufferSize = 1024;
            }
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            if (useSecurePort)
            {
                var localEp = new IPEndPoint(IPAddress.Any, GetLocalPort());
                socket.Bind(localEp);

            }

            if (socket.SendBufferSize < bufferSize)
            {
                socket.SendBufferSize = bufferSize;
            }
            if (socket.ReceiveBufferSize < bufferSize)
            {
                socket.ReceiveBufferSize = bufferSize;
            }
            //
            // Note: we don't do a
            //   socket.connect(host, this.port);
            // here anymore. XdrUdpEncodingStream long since then supported
            // specifying the destination of an ONC/RPC UDP packet when
            // start serialization. In addition, connecting a UDP socket disables
            // the socket's ability to receive broadcasts. Without connecting you
            // can send an ONC/RPC call to the broadcast address of the network
            // and receive multiple replies.
            //
            // Create the necessary encoding and decoding streams, so we can
            // communicate at all.
            //
            sendingXdr = new XdrUdpEncodingStream(socket, bufferSize);
            receivingXdr = new XdrUdpDecodingStream(socket, bufferSize);
        }
		/// <summary>
		/// Create a new instance of a <code>OncRpcUdpServerTransport</code> which
		/// encapsulates UDP/IP-based XDR streams of an ONC/RPC server.
		/// </summary>
		/// <remarks>
		/// Create a new instance of a <code>OncRpcUdpServerTransport</code> which
		/// encapsulates UDP/IP-based XDR streams of an ONC/RPC server. Using a
		/// server transport, ONC/RPC calls are received and the corresponding
		/// replies are sent back.
		/// This constructor is a convenience constructor for those transports
		/// handling only a single ONC/RPC program and version number.
		/// </remarks>
		/// <param name="dispatcher">
		/// Reference to interface of an object capable of
		/// dispatching (handling) ONC/RPC calls.
		/// </param>
		/// <param name="bindAddr">The local Internet Address the server will bind to.</param>
		/// <param name="port">
		/// Number of port where the server will wait for incoming
		/// calls.
		/// </param>
		/// <param name="info">
		/// Array of program and version number tuples of the ONC/RPC
		/// programs and versions handled by this transport.
		/// </param>
		/// <param name="bufferSize">
		/// Size of buffer for receiving and sending UDP/IP
		/// datagrams containing ONC/RPC call and reply messages.
		/// </param>
		/// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public OncRpcUdpServerTransport(OncRpcDispatchable dispatcher
			, IPAddress bindAddr, int port, OncRpcServerTransportRegistrationInfo
			[] info, int bufferSize) : base(dispatcher, port, info)
		{
			//
			// Make sure the buffer is large enough and resize system buffers
			// accordingly, if possible.
			//
			if (bufferSize < 1024)
			{
				bufferSize = 1024;
			}
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            if (bindAddr == null) bindAddr = IPAddress.Any;
            IPEndPoint localEP = new IPEndPoint(bindAddr, port);
            socket.Bind(localEP);
            if (port == 0)
			{
				this.port = ((IPEndPoint)(socket.LocalEndPoint)).Port;

			}
			if (socket.SendBufferSize < bufferSize)
			{
                socket.SendBufferSize = bufferSize;
			}
			if (socket.ReceiveBufferSize < bufferSize)
			{
                socket.ReceiveBufferSize = bufferSize;
			}
			//
			// Create the necessary encoding and decoding streams, so we can
			// communicate at all.
			//
			sendingXdr = new org.acplt.oncrpc.XdrUdpEncodingStream(socket, bufferSize);
			receivingXdr = new org.acplt.oncrpc.XdrUdpDecodingStream(socket, bufferSize);
		}