public SNMP_Request( SNMP_DataType dataType, SNMP_ReqType reqType,
                String oid, String communityString, byte[] setData)
        {
            request_id ++;
            
            reqId = request_id;
            
            this.reqType = reqType;
            this.dataType = dataType;
            
            binData = new byte[600];
            oidBytes = new byte[get_oid_len(oid)];
                        
            byte cmnty[] = communityString.getBytes();
            int community_string_len = cmnty.length;
            
            if (community_string_len >= 127)
            {
                community_string_len = 126;
            }
            
            
            int tmp_len = 0;
	
            
            // request for exactly one parameter
            
                    tmp_len += get_oid_len(oid);
                    if (reqType == SNMP_ReqType.SetRequest)
                    {
                        tmp_len += setData.length;
                        tmp_len += 4; // type and length for value
                    } else
                    {
                        tmp_len += 2; // type and length for value (null value)
                    }
                  
                    tmp_len += 2; // type and length for oid
                    tmp_len += 4; // varbind sequence (2 byte length field)

            tmp_len += 4; // varbind list sequence (2 byte length field)
            tmp_len += 3; // error index
            tmp_len += 3; // error
            tmp_len += 6; // request_id ( 4 byte integer )
            tmp_len += 4; // getResponse (2 byte length field)
            tmp_len += 2 + community_string_len; // communitystring, length < 127
            tmp_len += 3; // snmp_version
	
	    udpPacketLen =  tmp_len + 4; // the UDP packet length
            
            if (udpPacketLen > binData.length)
            {
                // TODO: error handling
            }
            
            int p = 0;
            
            binData[p + 0] = BER_SEQUENCE;
            binData[p + 1] = (byte) 0x82;
            binData[p + 2] = (byte) ((tmp_len >> 8) & 0xFF);
            binData[p + 3] = (byte) (tmp_len & 0xFF);
	
            p += 4;
	
            binData[p + 0] = BER_INTEGER;
            binData[p + 1] = 1;
            binData[p + 2] = 0;  // version = SNMPv1

            p += 3;

            
            
            binData[p + 0] = BER_OCTETSTRING;
            binData[p + 1] = (byte) (community_string_len);
            
            int i;
            for (i=0; i < community_string_len; i++)
            {
                binData[p + 2 + i] = cmnty[i]; // copy string
            }
            
            p += 2 + community_string_len;
	
            tmp_len -= 3 + 2 + community_string_len + 4;
            
            if (reqType == SNMP_ReqType.SetRequest)
            {
                binData[p + 0] = (byte) BER_SNMP_SET;
            } else
            {
                binData[p + 0] = (byte) BER_SNMP_GET;
            }
            binData[p + 1] = (byte) 0x82;
            binData[p + 2] = (byte) ((tmp_len >> 8) & 0xFF);
            binData[p + 3] = (byte) (tmp_len & 0xFF);
	
            p += 4;
	
            binData[p + 0] = BER_INTEGER;
            binData[p + 1] = 4;
            binData[p + 2] = (byte) ((reqId >> 24) & 0xFF);
            binData[p + 3] = (byte) ((reqId >> 16) & 0xFF);
            binData[p + 4] = (byte) ((reqId >> 8) & 0xFF);
            binData[p + 5] = (byte) (reqId & 0xFF);
	
            p += 6;

            binData[p + 0] = BER_INTEGER;
            binData[p + 1] = 1;
            binData[p + 2] = 0;  // error = 0
	
            p += 3;
	
            binData[p + 0] = BER_INTEGER;
            binData[p + 1] = 1;
            binData[p + 2] = 0;  // error index = 0
	
            p += 3;
	
            tmp_len -= 6 + 3 + 3 + 4;
	
            binData[p + 0] = BER_SEQUENCE;
            binData[p + 1] = (byte) 0x82;
            binData[p + 2] = (byte) ((tmp_len >> 8) & 0xFF);
            binData[p + 3] = (byte) (tmp_len & 0xFF);
	
            p += 4;
	
            // one parameter
                int oid_len = get_oid_len(oid);

                int t;
                
                if (reqType == SNMP_ReqType.SetRequest)
                {
                    t = setData.length;
                    t += 4; // type and length for value (2 byte length field)
                    
                } else
                {
                    t = 2; // // type and length for value (null value)
                }
                
                t += oid_len; // oid length
                t += 2; // type and length for oid


                binData[p + 0] = BER_SEQUENCE;
                binData[p + 1] = (byte) 0x82;
                binData[p + 2] = (byte) ((t >> 8) & 0xFF);
                binData[p + 3] = (byte) (t & 0xFF);

                p += 4;

                binData[p + 0] = (byte) BER_OID;
                binData[p + 1] = (byte) oid_len;

                oid_copy(binData, oidBytes, p + 2, oid);
             

                p += 2 + oid_len;

                if (reqType == SNMP_ReqType.SetRequest)                             
                {
                    
                    if (dataType == SNMP_DataType.Integer)
                    {
                        binData[p + 0] = BER_INTEGER;
                    }
                    else
                    {
                        binData[p + 0] = BER_OCTETSTRING;
                    }

                    binData[p + 1] = (byte) 0x82;
                    binData[p + 2] = (byte) ((setData.length >> 8) & 0xFF);
                    binData[p + 3] = (byte) (setData.length & 0xFF);
                  

                    for (i=0; i < setData.length; i++)
                    {
                        binData[p + 4 + i] = setData[i]; // copy data
                    }

                } else
                {
                    binData[p + 0] = BER_NULL;
                    binData[p + 1] = 0;
                }
        }