/// <exception cref="System.IO.IOException"/> public virtual void Run() { IPAddress IPAddress = Extensions.GetAddressByName(host); byte[] sendData = request.GetBytes(); byte[] receiveData = new byte[65535]; // Use the provided socket if there is one, else just make a new one. DatagramSocket socket = this.clientSocket == null ? new DatagramSocket() : this.clientSocket; try { DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.Length, IPAddress , port); socket.Send(sendPacket); socket.SetSoTimeout(500); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.Length ); socket.Receive(receivePacket); // Check reply status XDR xdr = new XDR(Arrays.CopyOfRange(receiveData, 0, receivePacket.GetLength())); RpcReply reply = RpcReply.Read(xdr); if (reply.GetState() != RpcReply.ReplyState.MsgAccepted) { throw new IOException("Request failed: " + reply.GetState()); } } finally { // If the client socket was passed in to this UDP client, it's on the // caller of this UDP client to close that socket. if (this.clientSocket == null) { socket.Close(); } } }