/// <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);
        }
示例#2
0
		/// <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) : 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 (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);
		}