Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new <code>OncRpcTcpClient</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>OncRpcTcpClient</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>OncRpcTcpClient</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">
        /// Size of receive and send buffers. In contrast to
        /// UDP-based ONC/RPC clients, messages larger than the specified
        /// buffer size can still be sent and received. The buffer is only
        /// necessary to handle the messages and the underlaying streams will
        /// break up long messages automatically into suitable pieces.
        /// Specifying zero will select the default buffer size (currently
        /// 8192 bytes).
        /// </param>
        /// <param name="timeout">
        /// Maximum timeout in milliseconds when connecting to
        /// the ONC/RPC server. If negative, a default implementation-specific
        /// timeout setting will apply. <i>Note that this timeout only applies
        /// to the connection phase, but <b>not</b> to later communication.</i>
        /// </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 OncRpcTcpClient(IPAddress host, int program, int version, int port
                               , int bufferSize, int timeout) : base(host, program, version, port, org.acplt.oncrpc.OncRpcProtocols
                                                                     .ONCRPC_TCP)
        {
            //
            // 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 == 0)
            {
                bufferSize = 8192;
            }
            // default setting
            if (bufferSize < 1024)
            {
                bufferSize = 1024;
            }
            //
            // Note that we use this.port at this time, because the superclass
            // might have resolved the port number in case the caller specified
            // simply 0 as the port number.
            //
            // Construct the socket and connect
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint endPoint = new IPEndPoint(host, this.port);

            socket.Connect(endPoint);
            if (timeout >= 0)
            {
                socket.SendTimeout    = timeout;
                socket.ReceiveTimeout = timeout;
            }
            socket.NoDelay = true;
            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.XdrTcpEncodingStream(socket, bufferSize);
            receivingXdr = new org.acplt.oncrpc.XdrTcpDecodingStream(socket, bufferSize);
        }
 /// <summary>
 /// Create a new instance of a <code>OncRpcTcpSConnectionerverTransport</code>
 /// which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
 /// </summary>
 /// <remarks>
 /// Create a new instance of a <code>OncRpcTcpSConnectionerverTransport</code>
 /// which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This
 /// particular server transport handles individual ONC/RPC connections over
 /// TCP/IP.
 /// </remarks>
 /// <param name="dispatcher">
 /// Reference to interface of an object capable of
 /// dispatching (handling) ONC/RPC calls.
 /// </param>
 /// <param name="socket">TCP/IP-based socket of new connection.</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 used when receiving and sending
 /// chunks of XDR fragments over TCP/IP. The fragments built up to
 /// form ONC/RPC call and reply messages.
 /// </param>
 /// <param name="parent">Parent server transport which created us.</param>
 /// <param name="transmissionTimeout">Inherited transmission timeout.</param>
 /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public OncRpcTcpConnectionServerTransport(org.acplt.oncrpc.server.OncRpcDispatchable
                                           dispatcher, Socket socket, org.acplt.oncrpc.server.OncRpcServerTransportRegistrationInfo
                                           [] info, int bufferSize, org.acplt.oncrpc.server.OncRpcTcpServerTransport parent
                                           , int transmissionTimeout) : base(dispatcher, 0, info)
 {
     this.parent = parent;
     this.transmissionTimeout = transmissionTimeout;
     //
     // Make sure the buffer is large enough and resize system buffers
     // accordingly, if possible.
     //
     if (bufferSize < 1024)
     {
         bufferSize = 1024;
     }
     this.socket = socket;
     this.port   = ((IPEndPoint)socket.RemoteEndPoint).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.XdrTcpEncodingStream(socket, bufferSize);
     receivingXdr = new org.acplt.oncrpc.XdrTcpDecodingStream(socket, bufferSize);
     //
     // Inherit the character encoding setting from the listening
     // transport (parent transport).
     //
     setCharacterEncoding(parent.getCharacterEncoding());
 }
		/// <summary>
		/// Create a new instance of a <code>OncRpcTcpSConnectionerverTransport</code>
		/// which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
		/// </summary>
		/// <remarks>
		/// Create a new instance of a <code>OncRpcTcpSConnectionerverTransport</code>
		/// which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This
		/// particular server transport handles individual ONC/RPC connections over
		/// TCP/IP.
		/// </remarks>
		/// <param name="dispatcher">
		/// Reference to interface of an object capable of
		/// dispatching (handling) ONC/RPC calls.
		/// </param>
		/// <param name="socket">TCP/IP-based socket of new connection.</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 used when receiving and sending
		/// chunks of XDR fragments over TCP/IP. The fragments built up to
		/// form ONC/RPC call and reply messages.
		/// </param>
		/// <param name="parent">Parent server transport which created us.</param>
		/// <param name="transmissionTimeout">Inherited transmission timeout.</param>
		/// <exception cref="org.acplt.oncrpc.OncRpcException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public OncRpcTcpConnectionServerTransport(org.acplt.oncrpc.server.OncRpcDispatchable
			 dispatcher, Socket socket, org.acplt.oncrpc.server.OncRpcServerTransportRegistrationInfo
			[] info, int bufferSize, org.acplt.oncrpc.server.OncRpcTcpServerTransport parent
			, int transmissionTimeout) : base(dispatcher, 0, info)
		{
			this.parent = parent;
			this.transmissionTimeout = transmissionTimeout;
			//
			// Make sure the buffer is large enough and resize system buffers
			// accordingly, if possible.
			//
			if (bufferSize < 1024)
			{
				bufferSize = 1024;
			}
			this.socket = socket;
			this.port = ((IPEndPoint)socket.RemoteEndPoint).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.XdrTcpEncodingStream(socket, bufferSize);
			receivingXdr = new org.acplt.oncrpc.XdrTcpDecodingStream(socket, bufferSize);
			//
			// Inherit the character encoding setting from the listening
			// transport (parent transport).
			//
			setCharacterEncoding(parent.getCharacterEncoding());
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Constructs a new <code>OncRpcTcpClient</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>OncRpcTcpClient</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>OncRpcTcpClient</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">
		/// Size of receive and send buffers. In contrast to
		/// UDP-based ONC/RPC clients, messages larger than the specified
		/// buffer size can still be sent and received. The buffer is only
		/// necessary to handle the messages and the underlaying streams will
		/// break up long messages automatically into suitable pieces.
		/// Specifying zero will select the default buffer size (currently
		/// 8192 bytes).
		/// </param>
		/// <param name="timeout">
		/// Maximum timeout in milliseconds when connecting to
		/// the ONC/RPC server. If negative, a default implementation-specific
		/// timeout setting will apply. <i>Note that this timeout only applies
		/// to the connection phase, but <b>not</b> to later communication.</i>
		/// </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 OncRpcTcpClient(IPAddress host, int program, int version, int port
			, int bufferSize, int timeout) : base(host, program, version, port, org.acplt.oncrpc.OncRpcProtocols
			.ONCRPC_TCP)
		{
			//
			// 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 == 0)
			{
				bufferSize = 8192;
			}
			// default setting
			if (bufferSize < 1024)
			{
				bufferSize = 1024;
			}
			//
			// Note that we use this.port at this time, because the superclass
			// might have resolved the port number in case the caller specified
			// simply 0 as the port number.
			//
            // Construct the socket and connect
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint endPoint = new IPEndPoint(host, this.port);
            socket.Connect(endPoint);
            if (timeout >= 0)
            {
                socket.SendTimeout = timeout;
                socket.ReceiveTimeout = timeout;
            }
            socket.NoDelay = true;
			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.XdrTcpEncodingStream(socket, bufferSize);
			receivingXdr = new org.acplt.oncrpc.XdrTcpDecodingStream(socket, bufferSize);
		}
 /// <summary>Close the server transport and free any resources associated with it.</summary>
 /// <remarks>
 /// Close the server transport and free any resources associated with it.
 /// <p>Note that the server transport is <b>not deregistered</b>. You'll
 /// have to do it manually if you need to do so. The reason for this
 /// behaviour is, that the portmapper removes all entries regardless of
 /// the protocol (TCP/IP or UDP/IP) for a given ONC/RPC program number
 /// and version.
 /// <p>Calling this method on a <code>OncRpcTcpServerTransport</code>
 /// results in the listening TCP network socket immediately being closed.
 /// The handler thread will therefore either terminate directly or when
 /// it tries to sent back replies.
 /// </remarks>
 public override void Close()
 {
     if (socket != null)
     {
         //
         // Since there is a non-zero chance of getting race conditions,
         // we now first set the socket instance member to null, before
         // we close the corresponding socket. This avoids null-pointer
         // exceptions in the method which waits for new requests: it is
         // possible that this method is awakened because the socket has
         // been closed before we could set the socket instance member to
         // null. Many thanks to Michael Smith for tracking down this one.
         //
         Socket deadSocket = socket;
         socket = null;
         try
         {
             deadSocket.Close();
         }
         catch (System.IO.IOException)
         {
         }
     }
     if (sendingXdr != null)
     {
         org.acplt.oncrpc.XdrEncodingStream deadXdrStream = sendingXdr;
         sendingXdr = null;
         try
         {
             deadXdrStream.Close();
         }
         catch (System.IO.IOException)
         {
         }
         catch (org.acplt.oncrpc.OncRpcException)
         {
         }
     }
     if (receivingXdr != null)
     {
         org.acplt.oncrpc.XdrDecodingStream deadXdrStream = receivingXdr;
         receivingXdr = null;
         try
         {
             deadXdrStream.Close();
         }
         catch (System.IO.IOException)
         {
         }
         catch (org.acplt.oncrpc.OncRpcException)
         {
         }
     }
     if (parent != null)
     {
         parent.removeTransport(this);
         parent = null;
     }
 }
Ejemplo n.º 6
0
 /// <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)
     {
         try
         {
             socket.Close();
         }
         catch (System.IO.IOException)
         {
         }
         socket = null;
     }
     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;
     }
 }