Exemplo n.º 1
0
        /// <summary>
        /// Connects to the Remote Command host server on the specified port using the specified system information and user.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static CommandConnection getConnection(final boolean isSSL, SystemInfo info, String user, String password, int commandPort, boolean compress) throws IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        public static CommandConnection getConnection(bool isSSL, SystemInfo info, string user, string password, int commandPort, bool compress)
        {
            if (commandPort < 0 || commandPort > 65535)
            {
                throw new IOException("Bad command port: " + commandPort);
            }
            CommandConnection conn = null;

            Socket commandServer = isSSL? SSLSocketFactory.Default.createSocket(info.System, commandPort) : new Socket(info.System, commandPort);
            Stream @in           = commandServer.InputStream;
            Stream @out          = commandServer.OutputStream;

            try
            {
                if (compress)
                {
                    throw new IOException("Experimental compression streams not enabled.");
                    //        in = new CompressionInputStream(in);
                    //        out = new CompressionOutputStream(new BufferedOutputStream(out));
                }

                // Exchange random seeds.
                HostOutputStream dout    = new HostOutputStream(compress ? @out : new BufferedOutputStream(@out));
                HostInputStream  din     = new HostInputStream(new BufferedInputStream(@in));
                string           jobName = connect(info, dout, din, 0xE008, user, password);

                string NLV = Conv.DefaultNLV;
                sendExchangeAttributesRequest(dout, NLV);
                dout.flush();

                int length = din.readInt();
                if (length < 20)
                {
                    throw DataStreamException.badLength("commandExchangeAttributes", length);
                }
                din.skipBytes(16);
                int rc = din.readShort();
                // We ignore the same return codes that JTOPEN ignores
                if (rc != 0x0100 && rc != 0x0104 && rc != 0x0105 && rc != 0x0106 && rc != 0x0107 && rc != 0x0108 && rc != 0)
                {
                    throw DataStreamException.badReturnCode("commandExchangeAttributes", rc);
                }
                int     ccsid    = din.readInt();
                sbyte[] nlvBytes = new sbyte[4];
                nlvBytes[0] = (sbyte)din.readByte();
                nlvBytes[1] = (sbyte)din.readByte();
                nlvBytes[2] = (sbyte)din.readByte();
                nlvBytes[3] = (sbyte)din.readByte();
                NLV         = Conv.ebcdicByteArrayToString(nlvBytes, 0, 4);
                // Server version
                din.skipBytes(4);

                int datastreamLevel = din.readShort();
                din.skipBytes(length - 36);
                din.end();

                conn = new CommandConnection(info, commandServer, din, dout, ccsid, datastreamLevel, user, jobName, NLV);
                return(conn);
            }
            finally
            {
                if (conn == null)
                {
                    @in.Close();
                    @out.Close();
                    commandServer.close();
                }
            }
        }